| ... | ... | @@ -335,9 +335,8 @@ static void check_type_compatibility(CodeGen *g, AstNode *node, TypeTableEntry * |
| 335 | 335 | if (expected_type == g->builtin_types.entry_invalid || actual_type == g->builtin_types.entry_invalid) |
| 336 | 336 | return; // already complained |
| 337 | 337 | if (actual_type == g->builtin_types.entry_unreachable) |
| 338 | | return; // TODO: is this true? |
| 338 | return; // sorry toots; gotta run. good luck with that expected type. |
| 339 | 339 | |
| 340 | | // TODO better error message |
| 341 | 340 | add_node_error(g, node, |
| 342 | 341 | buf_sprintf("type mismatch. expected %s. got %s", |
| 343 | 342 | buf_ptr(&expected_type->name), |
| ... | ... | @@ -632,14 +631,16 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import, |
| 632 | 631 | { |
| 633 | 632 | analyze_expression(g, import, context, g->builtin_types.entry_bool, node->data.if_expr.condition); |
| 634 | 633 | |
| 634 | TypeTableEntry *then_type = analyze_expression(g, import, context, expected_type, |
| 635 | node->data.if_expr.then_block); |
| 636 | |
| 635 | 637 | TypeTableEntry *else_type; |
| 636 | 638 | if (node->data.if_expr.else_node) { |
| 637 | 639 | else_type = analyze_expression(g, import, context, expected_type, node->data.if_expr.else_node); |
| 638 | 640 | } else { |
| 639 | 641 | else_type = g->builtin_types.entry_void; |
| 640 | 642 | } |
| 641 | | TypeTableEntry *then_type = analyze_expression(g, import, context, expected_type, |
| 642 | | node->data.if_expr.then_block); |
| 643 | |
| 643 | 644 | |
| 644 | 645 | TypeTableEntry *primary_type; |
| 645 | 646 | TypeTableEntry *other_type; |
| ... | ... | @@ -651,6 +652,7 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import, |
| 651 | 652 | other_type = else_type; |
| 652 | 653 | } |
| 653 | 654 | |
| 655 | check_type_compatibility(g, node, primary_type, other_type); |
| 654 | 656 | check_type_compatibility(g, node, expected_type, other_type); |
| 655 | 657 | return_type = primary_type; |
| 656 | 658 | break; |