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,
1691816918static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
1691916919 IrInstruction *msg = instruction->msg->other;
1692016920 if (type_is_invalid(msg->value.type))
16921 return ira->codegen->builtin_types.entry_invalid;
16921 return ir_unreach_error(ira);
1692216922
1692316923 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) {
1692416924 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);
1692616926 }
1692716927
1692816928 TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
1692916929 TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);
1693016930 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);
1693116931 if (type_is_invalid(casted_msg->value.type))
16932 return ira->codegen->builtin_types.entry_invalid;
16932 return ir_unreach_error(ira);
1693316933
1693416934 IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope,
1693516935 instruction->base.source_node, casted_msg);
test/compile_errors.zig+9
......@@ -1,6 +1,15 @@
11const tests = @import("tests.zig");
22
33pub 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
413 cases.add("@tagName used on union with no associated enum tag",
514 \\const FloatInt = extern union {
615 \\ Float: f32,