authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-29 18:59:58+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-29 21:44:08+02:00
logb2b1d421c35ba602ddfadf94190d956de3293c62
treed6e68593cd7c6504d12c1ddfa5de4d6b410c899e
parent4b0ef6a409a11946a999e277ed2a3f4b6120d0f5

Sema: add missing failWithBadMemberAccess to zirExport

The assumption that AstGen would error only holds when exporting a identifier not a namespace member.

2 files changed, 12 insertions(+), 1 deletions(-)

src/Sema.zig+2-1
......@@ -5391,7 +5391,8 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
53915391 const container_namespace = container_ty.getNamespace().?;
53925392
53935393 const maybe_index = try sema.lookupInNamespace(block, operand_src, container_namespace, decl_name, false);
5394 break :index_blk maybe_index.?; // AstGen would produce error in case of unidentified name
5394 break :index_blk maybe_index orelse
5395 return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name);
53955396 } else try sema.lookupIdentifier(block, operand_src, decl_name);
53965397 const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) {
53975398 error.NeededSourceLocation => {
test/cases/compile_errors/missing_member_in_namespace_export.zig created+10
......@@ -0,0 +1,10 @@
1const S = struct {};
2comptime {
3 @export(S.foo, .{ .name = "foo" });
4}
5
6// error
7// target=native
8//
9// :3:14: error: struct 'tmp.S' has no member named 'foo'
10// :1:11: note: struct declared here