From 1c2e889820e50e26654990750ac5ef0755996618 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 11 Jun 2019 13:44:09 -0400 Subject: [PATCH] fix struct and array init when result casted to anyerror!?T previous commit message is incorrect, it was only for anyerror!T --- BRANCH_TODO | 2 -- src/ir.cpp | 9 ++++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/BRANCH_TODO b/BRANCH_TODO index 881a2f7d2..854b2c0ee 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -1,8 +1,6 @@ Scratch pad for stuff to do before merging master ================================================= -struct & array init when the result is casted to anyerror!?T - uncomment all the behavior tests look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated diff --git a/src/ir.cpp b/src/ir.cpp index b841f8032..0b9956253 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -14951,7 +14951,14 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrIn if (actual_elem_type->id == ZigTypeIdOptional && implicit_elem_type->id != ZigTypeIdOptional) { return ir_analyze_unwrap_optional_payload(ira, &instruction->base, result_loc, false, true); } else if (actual_elem_type->id == ZigTypeIdErrorUnion && implicit_elem_type->id != ZigTypeIdErrorUnion) { - return ir_analyze_unwrap_error_payload(ira, &instruction->base, result_loc, false, true); + IrInstruction *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, &instruction->base, + result_loc, false, true); + ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type; + if (actual_payload_type->id == ZigTypeIdOptional && implicit_elem_type->id != ZigTypeIdOptional) { + return ir_analyze_unwrap_optional_payload(ira, &instruction->base, unwrapped_err_ptr, false, true); + } else { + return unwrapped_err_ptr; + } } return result_loc; }