diff --git a/src/analyze.cpp b/src/analyze.cpp index 8008bea68..b0f019602 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -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"); } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index e264d57b5..4bd6e9bc2 100644 --- a/test/compile_errors.zig +++ b/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 {