authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-05 10:48:53-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-05 10:48:53-04:00
log7a0948253636080e5abe59b938761ee7348a7025
treea8e49c415952acc8c2280bc8e1c46d19ce27bcd3
parent677eaf29b10df9b1dc461b37e7be78734b11ef19

fix crash when evaluating return type has compile error

closes #1058

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

src/analyze.cpp+2
......@@ -1018,6 +1018,8 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
10181018 }
10191019 if (fn_type_id->return_type != nullptr) {
10201020 ensure_complete_type(g, fn_type_id->return_type);
1021 if (type_is_invalid(fn_type_id->return_type))
1022 return g->builtin_types.entry_invalid;
10211023 } else {
10221024 zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447");
10231025 }
test/compile_errors.zig+16
......@@ -1,6 +1,22 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "error when evaluating return type",
6 \\const Foo = struct {
7 \\ map: i32(i32),
8 \\
9 \\ fn init() Foo {
10 \\ return undefined;
11 \\ }
12 \\};
13 \\export fn entry() void {
14 \\ var rule_set = try Foo.init();
15 \\}
16 ,
17 ".tmp_source.zig:2:13: error: invalid cast from type 'type' to 'i32'",
18 );
19
420 cases.add(
521 "slicing single-item pointer",
622 \\export fn entry(ptr: *i32) void {