Sema: check for astgen failures in semaStructFields

The struct might be a top level struct in which case it might not have Zir.

Closes #12548
This commit is contained in:
Veikka Tuominen 2022-08-21 17:07:22 +03:00
parent 6c020cdb76
commit b2f02a820f
2 changed files with 21 additions and 2 deletions

View file

@ -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);

View file

@ -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 {