Skip to content

Commit

Permalink
emit a compile error for @Panic called at compile time
Browse files Browse the repository at this point in the history
closes #706
  • Loading branch information
andrewrk committed Jan 18, 2018
1 parent 0b8f19f commit 0fc645a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ir.cpp
Expand Up @@ -14499,6 +14499,11 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio
if (type_is_invalid(msg->value.type))
return ira->codegen->builtin_types.entry_invalid;

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;
}

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);
Expand Down
8 changes: 8 additions & 0 deletions test/compile_errors.zig
@@ -1,6 +1,14 @@
const tests = @import("tests.zig");

pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("@panic called at compile time",
\\export fn entry() {
\\ comptime {
\\ @panic("aoeu");
\\ }
\\}
, "error: encountered @panic at compile-time");

cases.add("wrong return type for main",
\\pub fn main() -> f32 { }
, "error: expected return type of main to be 'u8', 'noreturn', 'void', or '%void'");
Expand Down

0 comments on commit 0fc645a

Please sign in to comment.