| ... | @@ -5827,12 +5827,25 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc | ... | @@ -5827,12 +5827,25 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 5827 | return true; | 5827 | return true; |
| 5828 | } | 5828 | } |
| 5829 | } else if ((other_type->id == TypeTableEntryIdNumLitFloat && const_val->data.x_bignum.kind == BigNumKindFloat) || | 5829 | } else if ((other_type->id == TypeTableEntryIdNumLitFloat && const_val->data.x_bignum.kind == BigNumKindFloat) || |
| 5830 | (other_type->id == TypeTableEntryIdNumLitInt && const_val->data.x_bignum.kind == BigNumKindInt )) { | 5830 | (other_type->id == TypeTableEntryIdNumLitInt && const_val->data.x_bignum.kind == BigNumKindInt )) |
| 5831 | return true; | 5831 | { |
| 5832 | } else if ((other_type->id == TypeTableEntryIdMaybe && | | |
| 5833 | other_type->data.maybe.child_type->id == TypeTableEntryIdInt && | | |
| 5834 | const_val->data.x_bignum.kind == BigNumKindInt)) { | | |
| 5835 | 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 | } |
| 5836 | } | 5849 | } |
| 5837 | | 5850 | |
| 5838 | 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"; |
| ... | @@ -5898,11 +5911,9 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -5898,11 +5911,9 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 5898 | // implicit conversion from T to %?T | 5911 | // implicit conversion from T to %?T |
| 5899 | if (expected_type->id == TypeTableEntryIdErrorUnion && | 5912 | if (expected_type->id == TypeTableEntryIdErrorUnion && |
| 5900 | expected_type->data.error.child_type->id == TypeTableEntryIdMaybe && | 5913 | expected_type->data.error.child_type->id == TypeTableEntryIdMaybe && |
| 5901 | ir_types_match_with_implicit_cast( | 5914 | ir_types_match_with_implicit_cast(ira, |
| 5902 | ira, | | |
| 5903 | expected_type->data.error.child_type->data.maybe.child_type, | 5915 | expected_type->data.error.child_type->data.maybe.child_type, |
| 5904 | actual_type, | 5916 | actual_type, value)) |
| 5905 | value)) | | |
| 5906 | { | 5917 | { |
| 5907 | return ImplicitCastMatchResultYes; | 5918 | return ImplicitCastMatchResultYes; |
| 5908 | } | 5919 | } |
| ... | @@ -7083,10 +7094,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -7083,10 +7094,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 7083 | // explicit cast from T to %?T | 7094 | // explicit cast from T to %?T |
| 7084 | if (wanted_type->id == TypeTableEntryIdErrorUnion && | 7095 | if (wanted_type->id == TypeTableEntryIdErrorUnion && |
| 7085 | wanted_type->data.error.child_type->id == TypeTableEntryIdMaybe && | 7096 | wanted_type->data.error.child_type->id == TypeTableEntryIdMaybe && |
| 7086 | actual_type->id != TypeTableEntryIdMaybe) { | 7097 | actual_type->id != TypeTableEntryIdMaybe) |
| 7087 | if (types_match_const_cast_only(wanted_type->data.error.child_type->data.maybe.child_type, actual_type) || | 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) || |
| 7088 | actual_type->id == TypeTableEntryIdNullLit || | 7101 | actual_type->id == TypeTableEntryIdNullLit || |
| 7089 | actual_type->id == TypeTableEntryIdNumLitInt ) { | 7102 | actual_type->id == TypeTableEntryIdNumLitInt || |
| | 7103 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| | 7104 | { |
| 7090 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error.child_type, value); | 7105 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error.child_type, value); |
| 7091 | if (type_is_invalid(cast1->value.type)) | 7106 | if (type_is_invalid(cast1->value.type)) |
| 7092 | return ira->codegen->invalid_instruction; | 7107 | return ira->codegen->invalid_instruction; |
| ... | @@ -7094,7 +7109,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -7094,7 +7109,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 7094 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); | 7109 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 7095 | if (type_is_invalid(cast2->value.type)) | 7110 | if (type_is_invalid(cast2->value.type)) |
| 7096 | return ira->codegen->invalid_instruction; | 7111 | return ira->codegen->invalid_instruction; |
| 7097 | | 7112 | |
| 7098 | return cast2; | 7113 | return cast2; |
| 7099 | } | 7114 | } |
| 7100 | } | 7115 | } |