Skip to content

Commit

Permalink
fix crash when compile error in analyzing @Panic call
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Mar 27, 2018
1 parent 0b7b319 commit 6cb99fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ir.cpp
Expand Up @@ -16918,18 +16918,18 @@ static TypeTableEntry *ir_analyze_instruction_can_implicit_cast(IrAnalyze *ira,
static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
IrInstruction *msg = instruction->msg->other;
if (type_is_invalid(msg->value.type))
return ira->codegen->builtin_types.entry_invalid;
return ir_unreach_error(ira);

if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) {
ir_add_error(ira, &instruction->base, buf_sprintf("encountered @panic at compile-time"));
return ira->codegen->builtin_types.entry_invalid;
return ir_unreach_error(ira);
}

TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);
IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);
if (type_is_invalid(casted_msg->value.type))
return ira->codegen->builtin_types.entry_invalid;
return ir_unreach_error(ira);

IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope,
instruction->base.source_node, casted_msg);
Expand Down
9 changes: 9 additions & 0 deletions test/compile_errors.zig
@@ -1,6 +1,15 @@
const tests = @import("tests.zig");

pub fn addCases(cases: &tests.CompileErrorContext) void {
cases.add("wrong type passed to @panic",
\\export fn entry() void {
\\ var e = error.Foo;
\\ @panic(e);
\\}
,
".tmp_source.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'");


cases.add("@tagName used on union with no associated enum tag",
\\const FloatInt = extern union {
\\ Float: f32,
Expand Down

0 comments on commit 6cb99fd

Please sign in to comment.