diff --git a/src/ir.cpp b/src/ir.cpp index 92ef48f50..2772108a2 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -17520,6 +17520,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) { ir_reset_result(call_instruction->result_loc); result_loc = nullptr; + } else { + call_instruction->base.value.type = impl_fn_type_id->return_type; + IrInstruction *casted_value = ir_implicit_cast(ira, &call_instruction->base, result_loc->value.type->data.pointer.child_type); + if (type_is_invalid(casted_value->value.type)) + return casted_value; } } } else if (call_instruction->is_async_call_builtin) { diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 35d462289..4008ff19e 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -109,6 +109,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'" ); + cases.add( + "generic function call assigned to incorrect type", + \\pub export fn entry() void { + \\ var res: []i32 = undefined; + \\ res = myAlloc(i32); + \\} + \\fn myAlloc(comptime arg: type) anyerror!arg{ + \\ unreachable; + \\} + , + "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32" + ); + cases.add( "asigning to struct or union fields that are not optionals with a function that returns an optional", \\fn maybe(is: bool) ?u8 {