authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-21 17:07:22+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-22 11:16:36+03:00
logb2f02a820f1ed46721ed55243cead52efed055d7
treedd5e19857ff0430a20bcb3f4a333451f9399a66e
parent6c020cdb767192757b6c4b43e2f14c5394760431

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

2 files changed, 21 insertions(+), 2 deletions(-)

src/Sema.zig+3-1
......@@ -27909,7 +27909,9 @@ fn resolveInferredErrorSetTy(
2790927909fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void {
2791027910 const gpa = mod.gpa;
2791127911 const decl_index = struct_obj.owner_decl;
27912 const zir = struct_obj.namespace.file_scope.zir;
27912 const file_scope = struct_obj.namespace.file_scope;
27913 if (file_scope.status != .success_zir) return error.AnalysisFail;
27914 const zir = file_scope.zir;
2791327915 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
2791427916 assert(extended.opcode == .struct_decl);
2791527917 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
test/compile_errors.zig+18-1
......@@ -184,7 +184,7 @@ pub fn addCases(ctx: *TestContext) !void {
184184 }
185185
186186 {
187 const case = ctx.obj("argument causes error ", .{});
187 const case = ctx.obj("argument causes error", .{});
188188 case.backend = .stage2;
189189
190190 case.addSourceFile("b.zig",
......@@ -208,6 +208,23 @@ pub fn addCases(ctx: *TestContext) !void {
208208 });
209209 }
210210
211 {
212 const case = ctx.obj("astgen failure in file struct", .{});
213 case.backend = .stage2;
214
215 case.addSourceFile("b.zig",
216 \\bad
217 );
218
219 case.addError(
220 \\pub export fn entry() void {
221 \\ _ = (@sizeOf(@import("b.zig")));
222 \\}
223 , &[_][]const u8{
224 ":1:1: error: struct field missing type",
225 });
226 }
227
211228 // TODO test this in stage2, but we won't even try in stage1
212229 //ctx.objErrStage1("inline fn calls itself indirectly",
213230 // \\export fn foo() void {