mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
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:
parent
6c020cdb76
commit
b2f02a820f
2 changed files with 21 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue