authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-19 22:54:32+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-26 14:32:34-05:00
log0e405c5fc52945a03711454e86c1caa7c72c4d02
treee4ce7066139e5ffe9f932dc3b9cb8f72883bb93d
parent7de138ad7cef1f9d1743a82f9a0419142484f24a
signature Commit is signed but in an unrecognized format.

add missing cast to call result type


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

src/ir.cpp+5
......@@ -17682,6 +17682,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1768217682 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
1768317683 ir_reset_result(call_instruction->result_loc);
1768417684 result_loc = nullptr;
17685 } else {
17686 call_instruction->base.value.type = return_type;
17687 IrInstruction *casted_value = ir_implicit_cast(ira, &call_instruction->base, result_loc->value.type->data.pointer.child_type);
17688 if (type_is_invalid(casted_value->value.type))
17689 return casted_value;
1768517690 }
1768617691 }
1768717692 } else if (call_instruction->is_async_call_builtin) {
test/compile_errors.zig+13
......@@ -96,6 +96,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
9696 "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'",
9797 );
9898
99 cases.add(
100 "function call assigned to incorrect type",
101 \\export fn entry() void {
102 \\ var arr: [4]f32 = undefined;
103 \\ arr = concat();
104 \\}
105 \\fn concat() [16]f32 {
106 \\ return [1]f32{0}**16;
107 \\}
108 ,
109 "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'"
110 );
111
99112 cases.add(
100113 "asigning to struct or union fields that are not optionals with a function that returns an optional",
101114 \\fn maybe(is: bool) ?u8 {