Skip to content

Commit

Permalink
fix crash when evaluating return type has compile error
Browse files Browse the repository at this point in the history
closes #1058
  • Loading branch information
andrewrk committed Jun 5, 2018
1 parent 677eaf2 commit 7a09482
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/analyze.cpp
Expand Up @@ -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");
}
Expand Down
16 changes: 16 additions & 0 deletions test/compile_errors.zig
@@ -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 {
Expand Down

1 comment on commit 7a09482

@isaachier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Please sign in to comment.