authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-01-07 19:20:57+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-07 15:06:22-05:00
log3607d9ee6821f524e2866f8ca44a5d577495d762
treebf42b093446092c2810bf1409628b5069c71aee8
parent688d02176c05763fc8dcb9e5f5b1e5a19dc98c50

Fix crash in struct initializer evaluation

Closes #4100

2 files changed, 14 insertions(+), 0 deletions(-)

src/ir.cpp+2
......@@ -17479,6 +17479,8 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1747917479 field->decl_node = value ? value->source_node : suspend_source_instr->source_node;
1748017480 if (value && instr_is_comptime(value)) {
1748117481 ZigValue *val = ir_resolve_const(ira, value, UndefOk);
17482 if (!val)
17483 return ira->codegen->invalid_instruction;
1748217484 field->is_comptime = true;
1748317485 field->init_val = create_const_vals(1);
1748417486 copy_const_val(field->init_val, val);
test/compile_errors.zig+12
......@@ -2,6 +2,18 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub 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
517 cases.addTest("repeated invalid field access to generic function returning type crashes compiler. #2655",
618 \\pub fn A() type {
719 \\ return Q;