Commit 4585cb1e2f

Wooster <wooster0@proton.me>
2023-09-21 18:13:41
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
1 parent 3fc7413
Changed files (3)
src/AstGen.zig
@@ -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;
src/Sema.zig
@@ -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
test/cases/compile_errors/@export_with_undeclared_identifier.zig
@@ -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'