diff --git a/src/ir.cpp b/src/ir.cpp index 9b6265e1e4..5fae82ceeb 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -17479,6 +17479,8 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s field->decl_node = value ? value->source_node : suspend_source_instr->source_node; if (value && instr_is_comptime(value)) { ZigValue *val = ir_resolve_const(ira, value, UndefOk); + if (!val) + return ira->codegen->invalid_instruction; field->is_comptime = true; field->init_val = create_const_vals(1); copy_const_val(field->init_val, val); diff --git a/test/compile_errors.zig b/test/compile_errors.zig index de48e84e03..7d5f0f308d 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,18 @@ const tests = @import("tests.zig"); const builtin = @import("builtin"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.addTest("error in struct initializer doesn't crash the compiler", + \\pub export fn entry() void { + \\ const bitfield = struct { + \\ e: u8, + \\ e: u8, + \\ }; + \\ var a = .{@sizeOf(bitfield)}; + \\} + , &[_][]const u8{ + "tmp.zig:4:9: error: duplicate struct field: 'e'", + }); + cases.addTest("repeated invalid field access to generic function returning type crashes compiler. #2655", \\pub fn A() type { \\ return Q;