Commit b2b1d421c3

Veikka Tuominen <git@vexu.eu>
2022-11-29 17:59:58
Sema: add missing failWithBadMemberAccess to zirExport
The assumption that AstGen would error only holds when exporting a identifier not a namespace member.
1 parent 4b0ef6a
Changed files (2)
src/Sema.zig
@@ -5391,7 +5391,8 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
         const container_namespace = container_ty.getNamespace().?;
 
         const maybe_index = try sema.lookupInNamespace(block, operand_src, container_namespace, decl_name, false);
-        break :index_blk maybe_index.?; // AstGen would produce error in case of unidentified name
+        break :index_blk maybe_index orelse
+            return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name);
     } else try sema.lookupIdentifier(block, operand_src, decl_name);
     const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) {
         error.NeededSourceLocation => {
test/cases/compile_errors/missing_member_in_namespace_export.zig
@@ -0,0 +1,10 @@
+const S = struct {};
+comptime {
+    @export(S.foo, .{ .name = "foo" });
+}
+
+// error
+// target=native
+//
+// :3:14: error: struct 'tmp.S' has no member named 'foo'
+// :1:11: note: struct declared here