| author | |
| committer | |
| log | 3607d9ee6821f524e2866f8ca44a5d577495d762 |
| tree | bf42b093446092c2810bf1409628b5069c71aee8 |
| parent | 688d02176c05763fc8dcb9e5f5b1e5a19dc98c50 |
Closes #41002 files changed, 14 insertions(+), 0 deletions(-)
src/ir.cpp+2| ... | @@ -17479,6 +17479,8 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -17479,6 +17479,8 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17479 | field->decl_node = value ? value->source_node : suspend_source_instr->source_node; | 17479 | field->decl_node = value ? value->source_node : suspend_source_instr->source_node; |
| 17480 | if (value && instr_is_comptime(value)) { | 17480 | if (value && instr_is_comptime(value)) { |
| 17481 | ZigValue *val = ir_resolve_const(ira, value, UndefOk); | 17481 | ZigValue *val = ir_resolve_const(ira, value, UndefOk); |
| 17482 | if (!val) | ||
| 17483 | return ira->codegen->invalid_instruction; | ||
| 17482 | field->is_comptime = true; | 17484 | field->is_comptime = true; |
| 17483 | field->init_val = create_const_vals(1); | 17485 | field->init_val = create_const_vals(1); |
| 17484 | copy_const_val(field->init_val, val); | 17486 | copy_const_val(field->init_val, val); |
test/compile_errors.zig+12| ... | @@ -2,6 +2,18 @@ const tests = @import("tests.zig"); | ... | @@ -2,6 +2,18 @@ const tests = @import("tests.zig"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.addTest("error in struct initializer doesn't crash the compiler", | ||
| 6 | \\pub export fn entry() void { | ||
| 7 | \\ const bitfield = struct { | ||
| 8 | \\ e: u8, | ||
| 9 | \\ e: u8, | ||
| 10 | \\ }; | ||
| 11 | \\ var a = .{@sizeOf(bitfield)}; | ||
| 12 | \\} | ||
| 13 | , &[_][]const u8{ | ||
| 14 | "tmp.zig:4:9: error: duplicate struct field: 'e'", | ||
| 15 | }); | ||
| 16 | |||
| 5 | cases.addTest("repeated invalid field access to generic function returning type crashes compiler. #2655", | 17 | cases.addTest("repeated invalid field access to generic function returning type crashes compiler. #2655", |
| 6 | \\pub fn A() type { | 18 | \\pub fn A() type { |
| 7 | \\ return Q; | 19 | \\ return Q; |