authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-20 07:54:47+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-26 14:32:37-05:00
log379d547603badb2667089c85454a2e3f5ede3342
tree47904e8bd6afaeb594247039513141287f040457
parent0e405c5fc52945a03711454e86c1caa7c72c4d02
signaturelock-open Commit is signed but in an unrecognized format.

add missing cast to generic function call result


2 files changed, 18 insertions(+), 0 deletions(-)

src/ir.cpp+5
...@@ -17520,6 +17520,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17520,6 +17520,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17520 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {17520 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
17521 ir_reset_result(call_instruction->result_loc);17521 ir_reset_result(call_instruction->result_loc);
17522 result_loc = nullptr;17522 result_loc = nullptr;
17523 } else {
17524 call_instruction->base.value.type = impl_fn_type_id->return_type;
17525 IrInstruction *casted_value = ir_implicit_cast(ira, &call_instruction->base, result_loc->value.type->data.pointer.child_type);
17526 if (type_is_invalid(casted_value->value.type))
17527 return casted_value;
17523 }17528 }
17524 }17529 }
17525 } else if (call_instruction->is_async_call_builtin) {17530 } else if (call_instruction->is_async_call_builtin) {
test/compile_errors.zig+13
...@@ -109,6 +109,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -109,6 +109,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
109 "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'"109 "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'"
110 );110 );
111111
112 cases.add(
113 "generic function call assigned to incorrect type",
114 \\pub export fn entry() void {
115 \\ var res: []i32 = undefined;
116 \\ res = myAlloc(i32);
117 \\}
118 \\fn myAlloc(comptime arg: type) anyerror!arg{
119 \\ unreachable;
120 \\}
121 ,
122 "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32"
123 );
124
112 cases.add(125 cases.add(
113 "asigning to struct or union fields that are not optionals with a function that returns an optional",126 "asigning to struct or union fields that are not optionals with a function that returns an optional",
114 \\fn maybe(is: bool) ?u8 {127 \\fn maybe(is: bool) ?u8 {