authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-27 15:07:45-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-27 15:07:45-04:00
log6cb99fdac3fb02d7e4e5a363295bae0dd3641a45
tree596dc91fb9208a0507dfb326198756037232906e
parent0b7b3190fd1121aa4e349740cff1faf213c94411

fix crash when compile error in analyzing @panic call


2 files changed, 12 insertions(+), 3 deletions(-)

src/ir.cpp+3-3
...@@ -16918,18 +16918,18 @@ static TypeTableEntry *ir_analyze_instruction_can_implicit_cast(IrAnalyze *ira,...@@ -16918,18 +16918,18 @@ static TypeTableEntry *ir_analyze_instruction_can_implicit_cast(IrAnalyze *ira,
16918static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {16918static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
16919 IrInstruction *msg = instruction->msg->other;16919 IrInstruction *msg = instruction->msg->other;
16920 if (type_is_invalid(msg->value.type))16920 if (type_is_invalid(msg->value.type))
16921 return ira->codegen->builtin_types.entry_invalid;16921 return ir_unreach_error(ira);
1692216922
16923 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) {16923 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) {
16924 ir_add_error(ira, &instruction->base, buf_sprintf("encountered @panic at compile-time"));16924 ir_add_error(ira, &instruction->base, buf_sprintf("encountered @panic at compile-time"));
16925 return ira->codegen->builtin_types.entry_invalid;16925 return ir_unreach_error(ira);
16926 }16926 }
1692716927
16928 TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);16928 TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
16929 TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);16929 TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);
16930 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);16930 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);
16931 if (type_is_invalid(casted_msg->value.type))16931 if (type_is_invalid(casted_msg->value.type))
16932 return ira->codegen->builtin_types.entry_invalid;16932 return ir_unreach_error(ira);
1693316933
16934 IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope,16934 IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope,
16935 instruction->base.source_node, casted_msg);16935 instruction->base.source_node, casted_msg);
test/compile_errors.zig+9
...@@ -1,6 +1,15 @@...@@ -1,6 +1,15 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.CompileErrorContext) void {3pub fn addCases(cases: &tests.CompileErrorContext) void {
4 cases.add("wrong type passed to @panic",
5 \\export fn entry() void {
6 \\ var e = error.Foo;
7 \\ @panic(e);
8 \\}
9 ,
10 ".tmp_source.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'");
11
12
4 cases.add("@tagName used on union with no associated enum tag",13 cases.add("@tagName used on union with no associated enum tag",
5 \\const FloatInt = extern union {14 \\const FloatInt = extern union {
6 \\ Float: f32,15 \\ Float: f32,