| ... | @@ -5826,12 +5826,26 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc | ... | @@ -5826,12 +5826,26 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 5826 | { | 5826 | { |
| 5827 | return true; | 5827 | return true; |
| 5828 | } | 5828 | } |
| 5829 | } else if ((other_type->id == TypeTableEntryIdNumLitFloat && | 5829 | } else if ((other_type->id == TypeTableEntryIdNumLitFloat && const_val->data.x_bignum.kind == BigNumKindFloat) || |
| 5830 | const_val->data.x_bignum.kind == BigNumKindFloat) || | 5830 | (other_type->id == TypeTableEntryIdNumLitInt && const_val->data.x_bignum.kind == BigNumKindInt )) |
| 5831 | (other_type->id == TypeTableEntryIdNumLitInt && | | |
| 5832 | const_val->data.x_bignum.kind == BigNumKindInt)) | | |
| 5833 | { | 5831 | { |
| 5834 | return true; | 5832 | return true; |
| | 5833 | } else if (other_type->id == TypeTableEntryIdMaybe) { |
| | 5834 | TypeTableEntry *child_type = other_type->data.maybe.child_type; |
| | 5835 | if ((child_type->id == TypeTableEntryIdNumLitFloat && const_val->data.x_bignum.kind == BigNumKindFloat) || |
| | 5836 | (child_type->id == TypeTableEntryIdNumLitInt && const_val->data.x_bignum.kind == BigNumKindInt )) |
| | 5837 | { |
| | 5838 | return true; |
| | 5839 | } else if (child_type->id == TypeTableEntryIdInt && const_val->data.x_bignum.kind == BigNumKindInt) { |
| | 5840 | if (bignum_fits_in_bits(&const_val->data.x_bignum, |
| | 5841 | child_type->data.integral.bit_count, |
| | 5842 | child_type->data.integral.is_signed)) |
| | 5843 | { |
| | 5844 | return true; |
| | 5845 | } |
| | 5846 | } else if (child_type->id == TypeTableEntryIdFloat && const_val->data.x_bignum.kind == BigNumKindFloat) { |
| | 5847 | return true; |
| | 5848 | } |
| 5835 | } | 5849 | } |
| 5836 | | 5850 | |
| 5837 | const char *num_lit_str = (const_val->data.x_bignum.kind == BigNumKindFloat) ? "float" : "integer"; | 5851 | const char *num_lit_str = (const_val->data.x_bignum.kind == BigNumKindFloat) ? "float" : "integer"; |
| ... | @@ -5894,6 +5908,16 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -5894,6 +5908,16 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 5894 | return ImplicitCastMatchResultYes; | 5908 | return ImplicitCastMatchResultYes; |
| 5895 | } | 5909 | } |
| 5896 | | 5910 | |
| | 5911 | // implicit conversion from T to %?T |
| | 5912 | if (expected_type->id == TypeTableEntryIdErrorUnion && |
| | 5913 | expected_type->data.error.child_type->id == TypeTableEntryIdMaybe && |
| | 5914 | ir_types_match_with_implicit_cast(ira, |
| | 5915 | expected_type->data.error.child_type->data.maybe.child_type, |
| | 5916 | actual_type, value)) |
| | 5917 | { |
| | 5918 | return ImplicitCastMatchResultYes; |
| | 5919 | } |
| | 5920 | |
| 5897 | // implicit widening conversion | 5921 | // implicit widening conversion |
| 5898 | if (expected_type->id == TypeTableEntryIdInt && | 5922 | if (expected_type->id == TypeTableEntryIdInt && |
| 5899 | actual_type->id == TypeTableEntryIdInt && | 5923 | actual_type->id == TypeTableEntryIdInt && |
| ... | @@ -7067,6 +7091,29 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -7067,6 +7091,29 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 7067 | return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type); | 7091 | return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type); |
| 7068 | } | 7092 | } |
| 7069 | | 7093 | |
| | 7094 | // explicit cast from T to %?T |
| | 7095 | if (wanted_type->id == TypeTableEntryIdErrorUnion && |
| | 7096 | wanted_type->data.error.child_type->id == TypeTableEntryIdMaybe && |
| | 7097 | actual_type->id != TypeTableEntryIdMaybe) |
| | 7098 | { |
| | 7099 | TypeTableEntry *wanted_child_type = wanted_type->data.error.child_type->data.maybe.child_type; |
| | 7100 | if (types_match_const_cast_only(wanted_child_type, actual_type) || |
| | 7101 | actual_type->id == TypeTableEntryIdNullLit || |
| | 7102 | actual_type->id == TypeTableEntryIdNumLitInt || |
| | 7103 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| | 7104 | { |
| | 7105 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error.child_type, value); |
| | 7106 | if (type_is_invalid(cast1->value.type)) |
| | 7107 | return ira->codegen->invalid_instruction; |
| | 7108 | |
| | 7109 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| | 7110 | if (type_is_invalid(cast2->value.type)) |
| | 7111 | return ira->codegen->invalid_instruction; |
| | 7112 | |
| | 7113 | return cast2; |
| | 7114 | } |
| | 7115 | } |
| | 7116 | |
| 7070 | // explicit cast from number literal to another type | 7117 | // explicit cast from number literal to another type |
| 7071 | // explicit cast from number literal to &const integer | 7118 | // explicit cast from number literal to &const integer |
| 7072 | if (actual_type->id == TypeTableEntryIdNumLitFloat || | 7119 | if (actual_type->id == TypeTableEntryIdNumLitFloat || |