| ... | ... | @@ -5826,11 +5826,12 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 5826 | 5826 | { |
| 5827 | 5827 | return true; |
| 5828 | 5828 | } |
| 5829 | | } else if ((other_type->id == TypeTableEntryIdNumLitFloat && |
| 5830 | | const_val->data.x_bignum.kind == BigNumKindFloat) || |
| 5831 | | (other_type->id == TypeTableEntryIdNumLitInt && |
| 5832 | | const_val->data.x_bignum.kind == BigNumKindInt)) |
| 5833 | | { |
| 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 )) { |
| 5831 | return true; |
| 5832 | } else if ((other_type->id == TypeTableEntryIdMaybe && |
| 5833 | other_type->data.maybe.child_type->id == TypeTableEntryIdInt && |
| 5834 | const_val->data.x_bignum.kind == BigNumKindInt)) { |
| 5834 | 5835 | return true; |
| 5835 | 5836 | } |
| 5836 | 5837 | |
| ... | ... | @@ -5894,6 +5895,18 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 5894 | 5895 | return ImplicitCastMatchResultYes; |
| 5895 | 5896 | } |
| 5896 | 5897 | |
| 5898 | // implicit conversion from T to %?T |
| 5899 | if (expected_type->id == TypeTableEntryIdErrorUnion && |
| 5900 | expected_type->data.error.child_type->id == TypeTableEntryIdMaybe && |
| 5901 | ir_types_match_with_implicit_cast( |
| 5902 | ira, |
| 5903 | expected_type->data.error.child_type->data.maybe.child_type, |
| 5904 | actual_type, |
| 5905 | value)) |
| 5906 | { |
| 5907 | return ImplicitCastMatchResultYes; |
| 5908 | } |
| 5909 | |
| 5897 | 5910 | // implicit widening conversion |
| 5898 | 5911 | if (expected_type->id == TypeTableEntryIdInt && |
| 5899 | 5912 | actual_type->id == TypeTableEntryIdInt && |
| ... | ... | @@ -7067,6 +7080,25 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 7067 | 7080 | return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type); |
| 7068 | 7081 | } |
| 7069 | 7082 | |
| 7083 | // explicit cast from T to %?T |
| 7084 | if (wanted_type->id == TypeTableEntryIdErrorUnion && |
| 7085 | wanted_type->data.error.child_type->id == TypeTableEntryIdMaybe && |
| 7086 | actual_type->id != TypeTableEntryIdMaybe) { |
| 7087 | if (types_match_const_cast_only(wanted_type->data.error.child_type->data.maybe.child_type, actual_type) || |
| 7088 | actual_type->id == TypeTableEntryIdNullLit || |
| 7089 | actual_type->id == TypeTableEntryIdNumLitInt ) { |
| 7090 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error.child_type, value); |
| 7091 | if (type_is_invalid(cast1->value.type)) |
| 7092 | return ira->codegen->invalid_instruction; |
| 7093 | |
| 7094 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 7095 | if (type_is_invalid(cast2->value.type)) |
| 7096 | return ira->codegen->invalid_instruction; |
| 7097 | |
| 7098 | return cast2; |
| 7099 | } |
| 7100 | } |
| 7101 | |
| 7070 | 7102 | // explicit cast from number literal to another type |
| 7071 | 7103 | // explicit cast from number literal to &const integer |
| 7072 | 7104 | if (actual_type->id == TypeTableEntryIdNumLitFloat || |