| ... | ... | @@ -2592,6 +2592,7 @@ static TypeTableEntry *resolve_expr_const_val_as_unsigned_num_lit(CodeGen *g, As |
| 2592 | 2592 | expr->const_val.ok = true; |
| 2593 | 2593 | |
| 2594 | 2594 | bignum_init_unsigned(&expr->const_val.data.x_bignum, x); |
| 2595 | |
| 2595 | 2596 | return g->builtin_types.entry_num_lit_int; |
| 2596 | 2597 | } |
| 2597 | 2598 | |
| ... | ... | @@ -2603,12 +2604,7 @@ static TypeTableEntry *resolve_expr_const_val_as_float_num_lit(CodeGen *g, AstNo |
| 2603 | 2604 | |
| 2604 | 2605 | bignum_init_float(&expr->const_val.data.x_bignum, x); |
| 2605 | 2606 | |
| 2606 | | if (expected_type) { |
| 2607 | | num_lit_fits_in_other_type(g, node, expected_type); |
| 2608 | | return expected_type; |
| 2609 | | } else { |
| 2610 | | return g->builtin_types.entry_num_lit_float; |
| 2611 | | } |
| 2607 | return g->builtin_types.entry_num_lit_float; |
| 2612 | 2608 | } |
| 2613 | 2609 | |
| 2614 | 2610 | static TypeTableEntry *resolve_expr_const_val_as_bignum_op(CodeGen *g, AstNode *node, |
| ... | ... | @@ -2915,12 +2911,12 @@ static TypeTableEntry *analyze_bool_bin_op_expr(CodeGen *g, ImportTableEntry *im |
| 2915 | 2911 | assert(node->type == NodeTypeBinOpExpr); |
| 2916 | 2912 | BinOpType bin_op_type = node->data.bin_op_expr.bin_op; |
| 2917 | 2913 | |
| 2918 | | AstNode *op1 = node->data.bin_op_expr.op1; |
| 2919 | | AstNode *op2 = node->data.bin_op_expr.op2; |
| 2920 | | TypeTableEntry *op1_type = analyze_expression(g, import, context, nullptr, op1); |
| 2921 | | TypeTableEntry *op2_type = analyze_expression(g, import, context, nullptr, op2); |
| 2914 | AstNode **op1 = &node->data.bin_op_expr.op1; |
| 2915 | AstNode **op2 = &node->data.bin_op_expr.op2; |
| 2916 | TypeTableEntry *op1_type = analyze_expression(g, import, context, nullptr, *op1); |
| 2917 | TypeTableEntry *op2_type = analyze_expression(g, import, context, nullptr, *op2); |
| 2922 | 2918 | |
| 2923 | | AstNode *op_nodes[] = {op1, op2}; |
| 2919 | AstNode *op_nodes[] = {*op1, *op2}; |
| 2924 | 2920 | TypeTableEntry *op_types[] = {op1_type, op2_type}; |
| 2925 | 2921 | |
| 2926 | 2922 | TypeTableEntry *resolved_type = resolve_peer_type_compatibility(g, import, context, node, |
| ... | ... | @@ -2942,8 +2938,8 @@ static TypeTableEntry *analyze_bool_bin_op_expr(CodeGen *g, ImportTableEntry *im |
| 2942 | 2938 | return g->builtin_types.entry_invalid; |
| 2943 | 2939 | } |
| 2944 | 2940 | |
| 2945 | | ConstExprValue *op1_val = &get_resolved_expr(op1)->const_val; |
| 2946 | | ConstExprValue *op2_val = &get_resolved_expr(op2)->const_val; |
| 2941 | ConstExprValue *op1_val = &get_resolved_expr(*op1)->const_val; |
| 2942 | ConstExprValue *op2_val = &get_resolved_expr(*op2)->const_val; |
| 2947 | 2943 | if (!op1_val->ok || !op2_val->ok) { |
| 2948 | 2944 | return g->builtin_types.entry_bool; |
| 2949 | 2945 | } |
| ... | ... | @@ -3637,6 +3633,17 @@ static TypeTableEntry *analyze_continue_expr(CodeGen *g, ImportTableEntry *impor |
| 3637 | 3633 | return g->builtin_types.entry_unreachable; |
| 3638 | 3634 | } |
| 3639 | 3635 | |
| 3636 | static TypeTableEntry *add_error_if_type_is_num_lit(CodeGen *g, TypeTableEntry *type_entry, AstNode *source_node) { |
| 3637 | if (type_entry->id == TypeTableEntryIdNumLitInt || |
| 3638 | type_entry->id == TypeTableEntryIdNumLitFloat) |
| 3639 | { |
| 3640 | add_node_error(g, source_node, buf_sprintf("unable to infer expression type")); |
| 3641 | return g->builtin_types.entry_invalid; |
| 3642 | } else { |
| 3643 | return type_entry; |
| 3644 | } |
| 3645 | } |
| 3646 | |
| 3640 | 3647 | static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockContext *parent_context, |
| 3641 | 3648 | TypeTableEntry *expected_type, AstNode *node, |
| 3642 | 3649 | AstNode **then_node, AstNode **else_node, bool cond_is_const, bool cond_bool_val) |
| ... | ... | @@ -3682,7 +3689,7 @@ static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockCon |
| 3682 | 3689 | } |
| 3683 | 3690 | |
| 3684 | 3691 | if (!cond_is_const) { |
| 3685 | | return result_type; |
| 3692 | return add_error_if_type_is_num_lit(g, result_type, node); |
| 3686 | 3693 | } |
| 3687 | 3694 | |
| 3688 | 3695 | ConstExprValue *other_const_val; |
| ... | ... | @@ -3692,7 +3699,7 @@ static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockCon |
| 3692 | 3699 | other_const_val = &get_resolved_expr(*else_node)->const_val; |
| 3693 | 3700 | } |
| 3694 | 3701 | if (!other_const_val->ok) { |
| 3695 | | return result_type; |
| 3702 | return add_error_if_type_is_num_lit(g, result_type, node); |
| 3696 | 3703 | } |
| 3697 | 3704 | |
| 3698 | 3705 | ConstExprValue *const_val = &get_resolved_expr(node)->const_val; |