authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2023-09-21 18:13:41+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-22 12:23:57-07:00
log4585cb1e2ff6afdb23748bd020ccf8e850550510
tree543dc8dd76da0bbb33dc90ada4af91afafd5a7cb
parent3fc74135749e32ba106572ed85a2e253b89fb0c6

AstGen: fix @export with undeclared identifier crashing

This required a third `if (found_already == null)` in another place in AstGen.zig for this special case of `@export`. Fixes #17188

3 files changed, 14 insertions(+), 1 deletions(-)

src/AstGen.zig+4
......@@ -8294,6 +8294,10 @@ fn builtinCall(
82948294 },
82958295 .top => break,
82968296 };
8297 if (found_already == null) {
8298 const ident_name = try astgen.identifierTokenString(ident_token);
8299 return astgen.failNode(params[0], "use of undeclared identifier '{s}'", .{ident_name});
8300 }
82978301 },
82988302 .field_access => {
82998303 const namespace_node = node_datas[params[0]].lhs;
src/Sema.zig+1-1
......@@ -6412,7 +6412,7 @@ fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPoo
64126412 }
64136413 namespace = mod.namespacePtr(namespace).parent.unwrap() orelse break;
64146414 }
6415 unreachable; // AstGen detects use of undeclared identifier errors.
6415 unreachable; // AstGen detects use of undeclared identifiers.
64166416}
64176417
64186418/// This looks up a member of a specific namespace. It is affected by `usingnamespace` but
test/cases/compile_errors/@export_with_undeclared_identifier.zig created+9
......@@ -0,0 +1,9 @@
1export fn a() void {
2 @export(bogus, .{ .name = "bogus_alias" });
3}
4
5// error
6// backend=stage2
7// target=native
8//
9// :2:13: error: use of undeclared identifier 'bogus'