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(...@@ -27909,7 +27909,9 @@ fn resolveInferredErrorSetTy(
27909fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void {27909fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void {
27910 const gpa = mod.gpa;27910 const gpa = mod.gpa;
27911 const decl_index = struct_obj.owner_decl;27911 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;
27913 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;27915 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
27914 assert(extended.opcode == .struct_decl);27916 assert(extended.opcode == .struct_decl);
27915 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);27917 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 {...@@ -184,7 +184,7 @@ pub fn addCases(ctx: *TestContext) !void {
184 }184 }
185185
186 {186 {
187 const case = ctx.obj("argument causes error ", .{});187 const case = ctx.obj("argument causes error", .{});
188 case.backend = .stage2;188 case.backend = .stage2;
189189
190 case.addSourceFile("b.zig",190 case.addSourceFile("b.zig",
...@@ -208,6 +208,23 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -208,6 +208,23 @@ pub fn addCases(ctx: *TestContext) !void {
208 });208 });
209 }209 }
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
211 // TODO test this in stage2, but we won't even try in stage1228 // TODO test this in stage2, but we won't even try in stage1
212 //ctx.objErrStage1("inline fn calls itself indirectly",229 //ctx.objErrStage1("inline fn calls itself indirectly",
213 // \\export fn foo() void {230 // \\export fn foo() void {