| ... | ... | @@ -3898,22 +3898,21 @@ static IrInstruction *ir_gen_address_of(IrBuilder *irb, Scope *scope, AstNode *n |
| 3898 | 3898 | align_value, bit_offset_start, bit_offset_end); |
| 3899 | 3899 | } |
| 3900 | 3900 | |
| 3901 | | static IrInstruction *ir_gen_err_assert_ok(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { |
| 3902 | | assert(node->type == NodeTypePrefixOpExpr); |
| 3903 | | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; |
| 3904 | | |
| 3901 | static IrInstruction *ir_gen_err_assert_ok(IrBuilder *irb, Scope *scope, AstNode *source_node, AstNode *expr_node, |
| 3902 | LVal lval) |
| 3903 | { |
| 3905 | 3904 | IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR); |
| 3906 | 3905 | if (err_union_ptr == irb->codegen->invalid_instruction) |
| 3907 | 3906 | return irb->codegen->invalid_instruction; |
| 3908 | 3907 | |
| 3909 | | IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, scope, node, err_union_ptr, true); |
| 3908 | IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, scope, source_node, err_union_ptr, true); |
| 3910 | 3909 | if (payload_ptr == irb->codegen->invalid_instruction) |
| 3911 | 3910 | return irb->codegen->invalid_instruction; |
| 3912 | 3911 | |
| 3913 | 3912 | if (lval.is_ptr) |
| 3914 | 3913 | return payload_ptr; |
| 3915 | 3914 | |
| 3916 | | return ir_build_load_ptr(irb, scope, node, payload_ptr); |
| 3915 | return ir_build_load_ptr(irb, scope, source_node, payload_ptr); |
| 3917 | 3916 | } |
| 3918 | 3917 | |
| 3919 | 3918 | static IrInstruction *ir_gen_maybe_assert_ok(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { |
| ... | ... | @@ -3965,7 +3964,7 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod |
| 3965 | 3964 | case PrefixOpError: |
| 3966 | 3965 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpError), lval); |
| 3967 | 3966 | case PrefixOpUnwrapError: |
| 3968 | | return ir_gen_err_assert_ok(irb, scope, node, lval); |
| 3967 | return ir_gen_err_assert_ok(irb, scope, node, node->data.prefix_op_expr.primary_expr, lval); |
| 3969 | 3968 | case PrefixOpUnwrapMaybe: |
| 3970 | 3969 | return ir_gen_maybe_assert_ok(irb, scope, node, lval); |
| 3971 | 3970 | } |
| ... | ... | @@ -5181,6 +5180,17 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN |
| 5181 | 5180 | AstNode *op2_node = node->data.unwrap_err_expr.op2; |
| 5182 | 5181 | AstNode *var_node = node->data.unwrap_err_expr.symbol; |
| 5183 | 5182 | |
| 5183 | if (op2_node->type == NodeTypeUnreachable) { |
| 5184 | if (var_node != nullptr) { |
| 5185 | assert(var_node->type == NodeTypeSymbol); |
| 5186 | Buf *var_name = var_node->data.symbol_expr.symbol; |
| 5187 | add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name))); |
| 5188 | return irb->codegen->invalid_instruction; |
| 5189 | } |
| 5190 | return ir_gen_err_assert_ok(irb, parent_scope, node, op1_node, LVAL_NONE); |
| 5191 | } |
| 5192 | |
| 5193 | |
| 5184 | 5194 | IrInstruction *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LVAL_PTR); |
| 5185 | 5195 | if (err_union_ptr == irb->codegen->invalid_instruction) |
| 5186 | 5196 | return irb->codegen->invalid_instruction; |