Skip to content

Commit 7a09482

Browse files
committedJun 5, 2018
fix crash when evaluating return type has compile error
closes #1058
·
0.15.20.3.0
1 parent 677eaf2 commit 7a09482

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
 

‎src/analyze.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
const tests = @import("tests.zig");
22

33
pub 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 {

1 commit comments

Comments
 (1)

isaachier commented on Jun 5, 2018

@isaachier
Contributor

Thanks!

Please sign in to comment.