add missing cast to generic function call result

This commit is contained in:
Vexu 2019-11-20 07:54:47 +02:00 committed by Andrew Kelley
parent 0e405c5fc5
commit 379d547603
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 18 additions and 0 deletions

View File

@ -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) {

View File

@ -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 {