diff --git a/src/Sema.zig b/src/Sema.zig index f3ddf21206..582299bc9e 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -27909,7 +27909,9 @@ fn resolveInferredErrorSetTy( fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void { const gpa = mod.gpa; const decl_index = struct_obj.owner_decl; - const zir = struct_obj.namespace.file_scope.zir; + const file_scope = struct_obj.namespace.file_scope; + if (file_scope.status != .success_zir) return error.AnalysisFail; + const zir = file_scope.zir; const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; assert(extended.opcode == .struct_decl); const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small); diff --git a/test/compile_errors.zig b/test/compile_errors.zig index f8ede21a9d..60de07d1e3 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -184,7 +184,7 @@ pub fn addCases(ctx: *TestContext) !void { } { - const case = ctx.obj("argument causes error ", .{}); + const case = ctx.obj("argument causes error", .{}); case.backend = .stage2; case.addSourceFile("b.zig", @@ -208,6 +208,23 @@ pub fn addCases(ctx: *TestContext) !void { }); } + { + const case = ctx.obj("astgen failure in file struct", .{}); + case.backend = .stage2; + + case.addSourceFile("b.zig", + \\bad + ); + + case.addError( + \\pub export fn entry() void { + \\ _ = (@sizeOf(@import("b.zig"))); + \\} + , &[_][]const u8{ + ":1:1: error: struct field missing type", + }); + } + // TODO test this in stage2, but we won't even try in stage1 //ctx.objErrStage1("inline fn calls itself indirectly", // \\export fn foo() void {