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
This commit is contained in:
Wooster 2023-09-21 18:13:41 +02:00 committed by Andrew Kelley
parent 3fc7413574
commit 4585cb1e2f
3 changed files with 14 additions and 1 deletions

View File

@ -8294,6 +8294,10 @@ fn builtinCall(
},
.top => break,
};
if (found_already == null) {
const ident_name = try astgen.identifierTokenString(ident_token);
return astgen.failNode(params[0], "use of undeclared identifier '{s}'", .{ident_name});
}
},
.field_access => {
const namespace_node = node_datas[params[0]].lhs;

View File

@ -6412,7 +6412,7 @@ fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPoo
}
namespace = mod.namespacePtr(namespace).parent.unwrap() orelse break;
}
unreachable; // AstGen detects use of undeclared identifier errors.
unreachable; // AstGen detects use of undeclared identifiers.
}
/// This looks up a member of a specific namespace. It is affected by `usingnamespace` but

View File

@ -0,0 +1,9 @@
export fn a() void {
@export(bogus, .{ .name = "bogus_alias" });
}
// error
// backend=stage2
// target=native
//
// :2:13: error: use of undeclared identifier 'bogus'