| ... | @@ -1951,17 +1951,7 @@ static TypeTableEntry *resolve_expr_const_val_as_unsigned_num_lit(CodeGen *g, As | ... | @@ -1951,17 +1951,7 @@ static TypeTableEntry *resolve_expr_const_val_as_unsigned_num_lit(CodeGen *g, As |
| 1951 | expr->const_val.ok = true; | 1951 | expr->const_val.ok = true; |
| 1952 | | 1952 | |
| 1953 | bignum_init_unsigned(&expr->const_val.data.x_bignum, x); | 1953 | bignum_init_unsigned(&expr->const_val.data.x_bignum, x); |
| 1954 | | 1954 | return g->builtin_types.entry_num_lit_int; |
| 1955 | if (expected_type) { | | |
| 1956 | if (expected_type->id == TypeTableEntryIdMaybe) { | | |
| 1957 | return g->builtin_types.entry_num_lit_int; | | |
| 1958 | } else { | | |
| 1959 | num_lit_fits_in_other_type(g, node, expected_type); | | |
| 1960 | return expected_type; | | |
| 1961 | } | | |
| 1962 | } else { | | |
| 1963 | return g->builtin_types.entry_num_lit_int; | | |
| 1964 | } | | |
| 1965 | } | 1955 | } |
| 1966 | | 1956 | |
| 1967 | static TypeTableEntry *resolve_expr_const_val_as_float_num_lit(CodeGen *g, AstNode *node, | 1957 | static TypeTableEntry *resolve_expr_const_val_as_float_num_lit(CodeGen *g, AstNode *node, |
| ... | @@ -3665,14 +3655,37 @@ static TypeTableEntry *analyze_return_expr(CodeGen *g, ImportTableEntry *import, | ... | @@ -3665,14 +3655,37 @@ static TypeTableEntry *analyze_return_expr(CodeGen *g, ImportTableEntry *import, |
| 3665 | normalize_parent_ptrs(node); | 3655 | normalize_parent_ptrs(node); |
| 3666 | } | 3656 | } |
| 3667 | | 3657 | |
| 3668 | if (node->data.return_expr.kind != ReturnKindUnconditional) { | | |
| 3669 | zig_panic("TODO analyze_return_expr conditional"); | | |
| 3670 | } | | |
| 3671 | | | |
| 3672 | TypeTableEntry *expected_return_type = get_return_type(context); | 3658 | TypeTableEntry *expected_return_type = get_return_type(context); |
| 3673 | analyze_expression(g, import, context, expected_return_type, node->data.return_expr.expr); | | |
| 3674 | | 3659 | |
| 3675 | return g->builtin_types.entry_unreachable; | 3660 | switch (node->data.return_expr.kind) { |
| | 3661 | case ReturnKindUnconditional: |
| | 3662 | { |
| | 3663 | analyze_expression(g, import, context, expected_return_type, node->data.return_expr.expr); |
| | 3664 | |
| | 3665 | return g->builtin_types.entry_unreachable; |
| | 3666 | } |
| | 3667 | case ReturnKindError: |
| | 3668 | { |
| | 3669 | TypeTableEntry *expected_err_type; |
| | 3670 | if (expected_type) { |
| | 3671 | expected_err_type = get_error_type(g, expected_type); |
| | 3672 | } else { |
| | 3673 | expected_err_type = nullptr; |
| | 3674 | } |
| | 3675 | TypeTableEntry *resolved_type = analyze_expression(g, import, context, expected_err_type, |
| | 3676 | node->data.return_expr.expr); |
| | 3677 | if (resolved_type->id == TypeTableEntryIdInvalid) { |
| | 3678 | return resolved_type; |
| | 3679 | } else if (resolved_type->id == TypeTableEntryIdErrorUnion) { |
| | 3680 | return resolved_type->data.error.child_type; |
| | 3681 | } else { |
| | 3682 | add_node_error(g, node->data.return_expr.expr, |
| | 3683 | buf_sprintf("expected error type, got '%s'", buf_ptr(&resolved_type->name))); |
| | 3684 | } |
| | 3685 | } |
| | 3686 | case ReturnKindMaybe: |
| | 3687 | zig_panic("TODO"); |
| | 3688 | } |
| 3676 | } | 3689 | } |
| 3677 | | 3690 | |
| 3678 | static TypeTableEntry *analyze_string_literal_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context, | 3691 | static TypeTableEntry *analyze_string_literal_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context, |