| ... | ... | @@ -3491,7 +3491,7 @@ static TypeTableEntry *analyze_continue_expr(CodeGen *g, ImportTableEntry *impor |
| 3491 | 3491 | return g->builtin_types.entry_unreachable; |
| 3492 | 3492 | } |
| 3493 | 3493 | |
| 3494 | | static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockContext *context, |
| 3494 | static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockContext *parent_context, |
| 3495 | 3495 | TypeTableEntry *expected_type, AstNode *node, |
| 3496 | 3496 | AstNode **then_node, AstNode **else_node, bool cond_is_const, bool cond_bool_val) |
| 3497 | 3497 | { |
| ... | ... | @@ -3500,8 +3500,27 @@ static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockCon |
| 3500 | 3500 | normalize_parent_ptrs(node); |
| 3501 | 3501 | } |
| 3502 | 3502 | |
| 3503 | | TypeTableEntry *then_type = analyze_expression(g, import, context, expected_type, *then_node); |
| 3504 | | TypeTableEntry *else_type = analyze_expression(g, import, context, expected_type, *else_node); |
| 3503 | BlockContext *then_context; |
| 3504 | BlockContext *else_context; |
| 3505 | if (cond_is_const) { |
| 3506 | if (cond_bool_val) { |
| 3507 | then_context = parent_context; |
| 3508 | else_context = new_block_context(node, parent_context); |
| 3509 | |
| 3510 | else_context->codegen_excluded = true; |
| 3511 | } else { |
| 3512 | then_context = new_block_context(node, parent_context); |
| 3513 | else_context = parent_context; |
| 3514 | |
| 3515 | then_context->codegen_excluded = true; |
| 3516 | } |
| 3517 | } else { |
| 3518 | then_context = parent_context; |
| 3519 | else_context = parent_context; |
| 3520 | } |
| 3521 | |
| 3522 | TypeTableEntry *then_type = analyze_expression(g, import, then_context, expected_type, *then_node); |
| 3523 | TypeTableEntry *else_type = analyze_expression(g, import, else_context, expected_type, *else_node); |
| 3505 | 3524 | |
| 3506 | 3525 | if (then_type->id == TypeTableEntryIdInvalid || else_type->id == TypeTableEntryIdInvalid) { |
| 3507 | 3526 | return g->builtin_types.entry_invalid; |
| ... | ... | @@ -3513,7 +3532,7 @@ static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockCon |
| 3513 | 3532 | } else { |
| 3514 | 3533 | AstNode *op_nodes[] = {*then_node, *else_node}; |
| 3515 | 3534 | TypeTableEntry *op_types[] = {then_type, else_type}; |
| 3516 | | result_type = resolve_peer_type_compatibility(g, import, context, node, op_nodes, op_types, 2); |
| 3535 | result_type = resolve_peer_type_compatibility(g, import, parent_context, node, op_nodes, op_types, 2); |
| 3517 | 3536 | } |
| 3518 | 3537 | |
| 3519 | 3538 | if (!cond_is_const) { |