authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-18 17:15:36-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-18 17:15:36-05:00
log0fc645ab7084c1812d367583b37218359b21c02c
treeb156e5bdc445b8b9b3b7763c358a195cf9438a1f
parent0b8f19fcba04cde35ca4831f37f8249d51da9432

emit a compile error for @panic called at compile time

closes #706

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

src/ir.cpp+5
...@@ -14499,6 +14499,11 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio...@@ -14499,6 +14499,11 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio
14499 if (type_is_invalid(msg->value.type))14499 if (type_is_invalid(msg->value.type))
14500 return ira->codegen->builtin_types.entry_invalid;14500 return ira->codegen->builtin_types.entry_invalid;
1450114501
14502 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) {
14503 ir_add_error(ira, &instruction->base, buf_sprintf("encountered @panic at compile-time"));
14504 return ira->codegen->builtin_types.entry_invalid;
14505 }
14506
14502 TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);14507 TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
14503 TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);14508 TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);
14504 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);14509 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);
test/compile_errors.zig+8
...@@ -1,6 +1,14 @@...@@ -1,6 +1,14 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.CompileErrorContext) {3pub fn addCases(cases: &tests.CompileErrorContext) {
4 cases.add("@panic called at compile time",
5 \\export fn entry() {
6 \\ comptime {
7 \\ @panic("aoeu");
8 \\ }
9 \\}
10 , "error: encountered @panic at compile-time");
11
4 cases.add("wrong return type for main",12 cases.add("wrong return type for main",
5 \\pub fn main() -> f32 { }13 \\pub fn main() -> f32 { }
6 , "error: expected return type of main to be 'u8', 'noreturn', 'void', or '%void'");14 , "error: expected return type of main to be 'u8', 'noreturn', 'void', or '%void'");