authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-01 00:27:10-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-01 00:27:22-04:00
logec6f15b0f5e1de517ac130241e3576f1afdd50cf
tree106b51c9b832ebdc647cfca308ddcc58a7a4effc
parent1f99899408367a16c13806369f94645c2001e68b
signaturelock-open Commit is signed but in an unrecognized format.

fix `@typeOf` an async function call of generic fn with error union type


2 files changed, 30 insertions(+), 14 deletions(-)

src/ir.cpp+19-14
......@@ -14934,7 +14934,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1493414934 PtrLenSingle, 0, 0, 0, false);
1493514935 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
1493614936 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
14937 if (fn_entry != nullptr) {
14937 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
1493814938 fn_entry->alloca_gen_list.append(alloca_gen);
1493914939 }
1494014940 result_loc->written = true;
......@@ -16058,6 +16058,18 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1605816058 }
1605916059
1606016060 FnTypeId *impl_fn_type_id = &impl_fn->type_entry->data.fn.fn_type_id;
16061
16062 if (fn_type_can_fail(impl_fn_type_id)) {
16063 parent_fn_entry->calls_or_awaits_errorable_fn = true;
16064 }
16065
16066 size_t impl_param_count = impl_fn_type_id->param_count;
16067 if (call_instruction->is_async) {
16068 IrInstruction *result = ir_analyze_async_call(ira, call_instruction, impl_fn, impl_fn->type_entry,
16069 nullptr, casted_args, impl_param_count, casted_new_stack);
16070 return ir_finish_anal(ira, result);
16071 }
16072
1606116073 IrInstruction *result_loc;
1606216074 if (call_instruction->is_async_call_builtin) {
1606316075 result_loc = get_async_call_result_loc(ira, call_instruction, impl_fn_type_id->return_type);
......@@ -16079,17 +16091,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1607916091 result_loc = nullptr;
1608016092 }
1608116093
16082 if (fn_type_can_fail(impl_fn_type_id)) {
16083 parent_fn_entry->calls_or_awaits_errorable_fn = true;
16084 }
16085
16086 size_t impl_param_count = impl_fn_type_id->param_count;
16087 if (call_instruction->is_async) {
16088 IrInstruction *result = ir_analyze_async_call(ira, call_instruction, impl_fn, impl_fn->type_entry,
16089 nullptr, casted_args, impl_param_count, casted_new_stack);
16090 return ir_finish_anal(ira, result);
16091 }
16092
1609316094 if (impl_fn_type_id->cc == CallingConventionAsync && parent_fn_entry->inferred_async_node == nullptr) {
1609416095 parent_fn_entry->inferred_async_node = fn_ref->source_node;
1609516096 parent_fn_entry->inferred_async_fn = impl_fn;
......@@ -16100,7 +16101,9 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1610016101 false, casted_new_stack, call_instruction->is_async_call_builtin, result_loc,
1610116102 impl_fn_type_id->return_type);
1610216103
16103 parent_fn_entry->call_list.append(new_call_instruction);
16104 if (get_scope_typeof(call_instruction->base.scope) == nullptr) {
16105 parent_fn_entry->call_list.append(new_call_instruction);
16106 }
1610416107
1610516108 return ir_finish_anal(ira, &new_call_instruction->base);
1610616109 }
......@@ -16243,7 +16246,9 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1624316246 IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref,
1624416247 call_param_count, casted_args, fn_inline, false, casted_new_stack,
1624516248 call_instruction->is_async_call_builtin, result_loc, return_type);
16246 parent_fn_entry->call_list.append(new_call_instruction);
16249 if (get_scope_typeof(call_instruction->base.scope) == nullptr) {
16250 parent_fn_entry->call_list.append(new_call_instruction);
16251 }
1624716252 return ir_finish_anal(ira, &new_call_instruction->base);
1624816253}
1624916254
test/stage1/behavior/async_fn.zig+11
......@@ -1020,3 +1020,14 @@ test "@asyncCall using the result location inside the frame" {
10201020 _ = async S.getAnswer(f, &data);
10211021 expect(data == 1234);
10221022}
1023
1024test "@typeOf an async function call of generic fn with error union type" {
1025 const S = struct {
1026 fn func(comptime x: var) anyerror!i32 {
1027 const T = @typeOf(async func(x));
1028 comptime expect(T == @typeOf(@frame()).Child);
1029 return undefined;
1030 }
1031 };
1032 _ = async S.func(i32);
1033}