commit b2b1d421c35ba602ddfadf94190d956de3293c62 (tree)
parent 4b0ef6a409a11946a999e277ed2a3f4b6120d0f5
Author: Veikka Tuominen <git@vexu.eu>
Date: Tue, 29 Nov 2022 18:59:58 +0200
Sema: add missing failWithBadMemberAccess to zirExport
The assumption that AstGen would error only holds when exporting
a identifier not a namespace member.
Diffstat:
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/Sema.zig b/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 => {
diff --git a/test/cases/compile_errors/missing_member_in_namespace_export.zig b/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