fix crash when evaluating return type has compile error

closes #1058
This commit is contained in:
Andrew Kelley 2018-06-05 10:48:53 -04:00
parent 677eaf29b1
commit 7a09482536
2 changed files with 18 additions and 0 deletions

View File

@ -1018,6 +1018,8 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
}
if (fn_type_id->return_type != nullptr) {
ensure_complete_type(g, fn_type_id->return_type);
if (type_is_invalid(fn_type_id->return_type))
return g->builtin_types.entry_invalid;
} else {
zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447");
}

View File

@ -1,6 +1,22 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"error when evaluating return type",
\\const Foo = struct {
\\ map: i32(i32),
\\
\\ fn init() Foo {
\\ return undefined;
\\ }
\\};
\\export fn entry() void {
\\ var rule_set = try Foo.init();
\\}
,
".tmp_source.zig:2:13: error: invalid cast from type 'type' to 'i32'",
);
cases.add(
"slicing single-item pointer",
\\export fn entry(ptr: *i32) void {