| ... | @@ -6424,12 +6424,23 @@ enum ImplicitCastMatchResult { | ... | @@ -6424,12 +6424,23 @@ enum ImplicitCastMatchResult { |
| 6424 | static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, TypeTableEntry *expected_type, | 6424 | static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, TypeTableEntry *expected_type, |
| 6425 | TypeTableEntry *actual_type, IrInstruction *value) | 6425 | TypeTableEntry *actual_type, IrInstruction *value) |
| 6426 | { | 6426 | { |
| 6427 | if (types_match_const_cast_only(ira->codegen, expected_type, actual_type)) { | 6427 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira->codegen, expected_type, actual_type); |
| | 6428 | if (const_cast_result.id == ConstCastResultIdOk) { |
| 6428 | return ImplicitCastMatchResultYes; | 6429 | return ImplicitCastMatchResultYes; |
| 6429 | } | 6430 | } |
| 6430 | | 6431 | |
| 6431 | // if we got here with error sets, make an error showing the incompatibilities | 6432 | // if we got here with error sets, make an error showing the incompatibilities |
| 6432 | if (expected_typek | 6433 | if (const_cast_result.id == ConstCastResultIdErrSet) { |
| | 6434 | ErrorMsg *msg = ir_add_error(ira, value, |
| | 6435 | buf_sprintf("expected '%s', found '%s'", buf_ptr(&expected_type->name), buf_ptr(&actual_type->name))); |
| | 6436 | for (size_t i = 0; i < const_cast_result.data.error_set.missing_errors.length; i += 1) { |
| | 6437 | ErrorTableEntry *error_entry = const_cast_result.data.error_set.missing_errors.at(i); |
| | 6438 | add_error_note(ira->codegen, msg, error_entry->decl_node, |
| | 6439 | buf_sprintf("'error.%s' not a member of destination error set", buf_ptr(&error_entry->name))); |
| | 6440 | } |
| | 6441 | |
| | 6442 | return ImplicitCastMatchResultReportedError; |
| | 6443 | } |
| 6433 | | 6444 | |
| 6434 | // implicit conversion from anything to var | 6445 | // implicit conversion from anything to var |
| 6435 | if (expected_type->id == TypeTableEntryIdVar) { | 6446 | if (expected_type->id == TypeTableEntryIdVar) { |
| ... | @@ -6508,7 +6519,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -6508,7 +6519,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6508 | assert(ptr_type->id == TypeTableEntryIdPointer); | 6519 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6509 | | 6520 | |
| 6510 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 6521 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 6511 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 6522 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 6512 | { | 6523 | { |
| 6513 | return ImplicitCastMatchResultYes; | 6524 | return ImplicitCastMatchResultYes; |
| 6514 | } | 6525 | } |
| ... | @@ -6527,7 +6538,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -6527,7 +6538,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6527 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; | 6538 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; |
| 6528 | | 6539 | |
| 6529 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && | 6540 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && |
| 6530 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type)) | 6541 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type).id == ConstCastResultIdOk) |
| 6531 | { | 6542 | { |
| 6532 | return ImplicitCastMatchResultYes; | 6543 | return ImplicitCastMatchResultYes; |
| 6533 | } | 6544 | } |
| ... | @@ -6543,7 +6554,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -6543,7 +6554,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6543 | expected_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; | 6554 | expected_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 6544 | assert(ptr_type->id == TypeTableEntryIdPointer); | 6555 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6545 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 6556 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 6546 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 6557 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 6547 | { | 6558 | { |
| 6548 | return ImplicitCastMatchResultYes; | 6559 | return ImplicitCastMatchResultYes; |
| 6549 | } | 6560 | } |
| ... | @@ -6558,7 +6569,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -6558,7 +6569,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6558 | expected_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; | 6569 | expected_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 6559 | assert(ptr_type->id == TypeTableEntryIdPointer); | 6570 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6560 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 6571 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 6561 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 6572 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 6562 | { | 6573 | { |
| 6563 | return ImplicitCastMatchResultYes; | 6574 | return ImplicitCastMatchResultYes; |
| 6564 | } | 6575 | } |
| ... | @@ -6638,7 +6649,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -6638,7 +6649,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6638 | // implicitly take a const pointer to something | 6649 | // implicitly take a const pointer to something |
| 6639 | if (!type_requires_comptime(actual_type)) { | 6650 | if (!type_requires_comptime(actual_type)) { |
| 6640 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); | 6651 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); |
| 6641 | if (types_match_const_cast_only(ira->codegen, expected_type, const_ptr_actual)) { | 6652 | if (types_match_const_cast_only(ira->codegen, expected_type, const_ptr_actual).id == ConstCastResultIdOk) { |
| 6642 | return ImplicitCastMatchResultYes; | 6653 | return ImplicitCastMatchResultYes; |
| 6643 | } | 6654 | } |
| 6644 | } | 6655 | } |
| ... | @@ -6742,20 +6753,31 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6742,20 +6753,31 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6742 | if (cur_is_superset) { | 6753 | if (cur_is_superset) { |
| 6743 | err_set_type = cur_type; | 6754 | err_set_type = cur_type; |
| 6744 | prev_inst = cur_inst; | 6755 | prev_inst = cur_inst; |
| | 6756 | assert(errors != nullptr); |
| 6745 | continue; | 6757 | continue; |
| 6746 | } | 6758 | } |
| 6747 | | 6759 | |
| 6748 | // neither of them are supersets. so we invent a new error set type that is a union of both of them | 6760 | // neither of them are supersets. so we invent a new error set type that is a union of both of them |
| 6749 | err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type); | 6761 | err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type); |
| | 6762 | assert(errors != nullptr); |
| 6750 | continue; | 6763 | continue; |
| 6751 | } else if (cur_type->id == TypeTableEntryIdErrorUnion) { | 6764 | } else if (cur_type->id == TypeTableEntryIdErrorUnion) { |
| | 6765 | if (err_set_type == ira->codegen->builtin_types.entry_global_error_set) { |
| | 6766 | prev_inst = cur_inst; |
| | 6767 | continue; |
| | 6768 | } |
| | 6769 | TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| | 6770 | if (cur_err_set_type == ira->codegen->builtin_types.entry_global_error_set) { |
| | 6771 | err_set_type = ira->codegen->builtin_types.entry_global_error_set; |
| | 6772 | prev_inst = cur_inst; |
| | 6773 | continue; |
| | 6774 | } |
| 6752 | // test if err_set_type is a subset of cur_type's error set | 6775 | // test if err_set_type is a subset of cur_type's error set |
| 6753 | // unset everything in errors | 6776 | // unset everything in errors |
| 6754 | for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { | 6777 | for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { |
| 6755 | ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i]; | 6778 | ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i]; |
| 6756 | errors[error_entry->value] = nullptr; | 6779 | errors[error_entry->value] = nullptr; |
| 6757 | } | 6780 | } |
| 6758 | TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; | | |
| 6759 | for (uint32_t i = 0; i < cur_err_set_type->data.error_set.err_count; i += 1) { | 6781 | for (uint32_t i = 0; i < cur_err_set_type->data.error_set.err_count; i += 1) { |
| 6760 | ErrorTableEntry *error_entry = cur_err_set_type->data.error_set.errors[i]; | 6782 | ErrorTableEntry *error_entry = cur_err_set_type->data.error_set.errors[i]; |
| 6761 | errors[error_entry->value] = error_entry; | 6783 | errors[error_entry->value] = error_entry; |
| ... | @@ -6772,12 +6794,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6772,12 +6794,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6772 | if (cur_is_superset) { | 6794 | if (cur_is_superset) { |
| 6773 | err_set_type = cur_err_set_type; | 6795 | err_set_type = cur_err_set_type; |
| 6774 | prev_inst = cur_inst; | 6796 | prev_inst = cur_inst; |
| | 6797 | assert(errors != nullptr); |
| 6775 | continue; | 6798 | continue; |
| 6776 | } | 6799 | } |
| 6777 | | 6800 | |
| 6778 | // not a subset. invent new error set type, union of both of them | 6801 | // not a subset. invent new error set type, union of both of them |
| 6779 | err_set_type = get_error_set_union(ira->codegen, errors, cur_err_set_type, err_set_type); | 6802 | err_set_type = get_error_set_union(ira->codegen, errors, cur_err_set_type, err_set_type); |
| 6780 | prev_inst = cur_inst; | 6803 | prev_inst = cur_inst; |
| | 6804 | assert(errors != nullptr); |
| 6781 | continue; | 6805 | continue; |
| 6782 | } else { | 6806 | } else { |
| 6783 | prev_inst = cur_inst; | 6807 | prev_inst = cur_inst; |
| ... | @@ -6820,15 +6844,16 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6820,15 +6844,16 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6820 | } | 6844 | } |
| 6821 | // not a subset. invent new error set type, union of both of them | 6845 | // not a subset. invent new error set type, union of both of them |
| 6822 | err_set_type = get_error_set_union(ira->codegen, errors, err_set_type, cur_type); | 6846 | err_set_type = get_error_set_union(ira->codegen, errors, err_set_type, cur_type); |
| | 6847 | assert(errors != nullptr); |
| 6823 | continue; | 6848 | continue; |
| 6824 | } | 6849 | } |
| 6825 | } | 6850 | } |
| 6826 | | 6851 | |
| 6827 | if (types_match_const_cast_only(ira->codegen, prev_type, cur_type)) { | 6852 | if (types_match_const_cast_only(ira->codegen, prev_type, cur_type).id == ConstCastResultIdOk) { |
| 6828 | continue; | 6853 | continue; |
| 6829 | } | 6854 | } |
| 6830 | | 6855 | |
| 6831 | if (types_match_const_cast_only(ira->codegen, cur_type, prev_type)) { | 6856 | if (types_match_const_cast_only(ira->codegen, cur_type, prev_type).id == ConstCastResultIdOk) { |
| 6832 | prev_inst = cur_inst; | 6857 | prev_inst = cur_inst; |
| 6833 | continue; | 6858 | continue; |
| 6834 | } | 6859 | } |
| ... | @@ -6851,26 +6876,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6851,26 +6876,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6851 | } | 6876 | } |
| 6852 | | 6877 | |
| 6853 | if (prev_type->id == TypeTableEntryIdErrorUnion && | 6878 | if (prev_type->id == TypeTableEntryIdErrorUnion && |
| 6854 | types_match_const_cast_only(ira->codegen, prev_type->data.error_union.payload_type, cur_type)) | 6879 | types_match_const_cast_only(ira->codegen, prev_type->data.error_union.payload_type, cur_type).id == ConstCastResultIdOk) |
| 6855 | { | 6880 | { |
| 6856 | continue; | 6881 | continue; |
| 6857 | } | 6882 | } |
| 6858 | | 6883 | |
| 6859 | if (cur_type->id == TypeTableEntryIdErrorUnion && | 6884 | if (cur_type->id == TypeTableEntryIdErrorUnion && |
| 6860 | types_match_const_cast_only(ira->codegen, cur_type->data.error_union.payload_type, prev_type)) | 6885 | types_match_const_cast_only(ira->codegen, cur_type->data.error_union.payload_type, prev_type).id == ConstCastResultIdOk) |
| 6861 | { | 6886 | { |
| 6862 | prev_inst = cur_inst; | 6887 | prev_inst = cur_inst; |
| 6863 | continue; | 6888 | continue; |
| 6864 | } | 6889 | } |
| 6865 | | 6890 | |
| 6866 | if (prev_type->id == TypeTableEntryIdMaybe && | 6891 | if (prev_type->id == TypeTableEntryIdMaybe && |
| 6867 | types_match_const_cast_only(ira->codegen, prev_type->data.maybe.child_type, cur_type)) | 6892 | types_match_const_cast_only(ira->codegen, prev_type->data.maybe.child_type, cur_type).id == ConstCastResultIdOk) |
| 6868 | { | 6893 | { |
| 6869 | continue; | 6894 | continue; |
| 6870 | } | 6895 | } |
| 6871 | | 6896 | |
| 6872 | if (cur_type->id == TypeTableEntryIdMaybe && | 6897 | if (cur_type->id == TypeTableEntryIdMaybe && |
| 6873 | types_match_const_cast_only(ira->codegen, cur_type->data.maybe.child_type, prev_type)) | 6898 | types_match_const_cast_only(ira->codegen, cur_type->data.maybe.child_type, prev_type).id == ConstCastResultIdOk) |
| 6874 | { | 6899 | { |
| 6875 | prev_inst = cur_inst; | 6900 | prev_inst = cur_inst; |
| 6876 | continue; | 6901 | continue; |
| ... | @@ -6908,7 +6933,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6908,7 +6933,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6908 | | 6933 | |
| 6909 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && | 6934 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && |
| 6910 | cur_type->data.array.len != prev_type->data.array.len && | 6935 | cur_type->data.array.len != prev_type->data.array.len && |
| 6911 | types_match_const_cast_only(ira->codegen, cur_type->data.array.child_type, prev_type->data.array.child_type)) | 6936 | types_match_const_cast_only(ira->codegen, cur_type->data.array.child_type, prev_type->data.array.child_type).id == ConstCastResultIdOk) |
| 6912 | { | 6937 | { |
| 6913 | convert_to_const_slice = true; | 6938 | convert_to_const_slice = true; |
| 6914 | prev_inst = cur_inst; | 6939 | prev_inst = cur_inst; |
| ... | @@ -6917,7 +6942,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6917,7 +6942,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6917 | | 6942 | |
| 6918 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && | 6943 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && |
| 6919 | cur_type->data.array.len != prev_type->data.array.len && | 6944 | cur_type->data.array.len != prev_type->data.array.len && |
| 6920 | types_match_const_cast_only(ira->codegen, prev_type->data.array.child_type, cur_type->data.array.child_type)) | 6945 | types_match_const_cast_only(ira->codegen, prev_type->data.array.child_type, cur_type->data.array.child_type).id == ConstCastResultIdOk) |
| 6921 | { | 6946 | { |
| 6922 | convert_to_const_slice = true; | 6947 | convert_to_const_slice = true; |
| 6923 | continue; | 6948 | continue; |
| ... | @@ -6927,7 +6952,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6927,7 +6952,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6927 | (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || | 6952 | (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 6928 | cur_type->data.array.len == 0) && | 6953 | cur_type->data.array.len == 0) && |
| 6929 | types_match_const_cast_only(ira->codegen, prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, | 6954 | types_match_const_cast_only(ira->codegen, prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, |
| 6930 | cur_type->data.array.child_type)) | 6955 | cur_type->data.array.child_type).id == ConstCastResultIdOk) |
| 6931 | { | 6956 | { |
| 6932 | convert_to_const_slice = false; | 6957 | convert_to_const_slice = false; |
| 6933 | continue; | 6958 | continue; |
| ... | @@ -6937,7 +6962,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6937,7 +6962,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6937 | (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || | 6962 | (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 6938 | prev_type->data.array.len == 0) && | 6963 | prev_type->data.array.len == 0) && |
| 6939 | types_match_const_cast_only(ira->codegen, cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, | 6964 | types_match_const_cast_only(ira->codegen, cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, |
| 6940 | prev_type->data.array.child_type)) | 6965 | prev_type->data.array.child_type).id == ConstCastResultIdOk) |
| 6941 | { | 6966 | { |
| 6942 | prev_inst = cur_inst; | 6967 | prev_inst = cur_inst; |
| 6943 | convert_to_const_slice = false; | 6968 | convert_to_const_slice = false; |
| ... | @@ -8059,7 +8084,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8059,7 +8084,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8059 | return value; | 8084 | return value; |
| 8060 | | 8085 | |
| 8061 | // explicit match or non-const to const | 8086 | // explicit match or non-const to const |
| 8062 | if (types_match_const_cast_only(ira->codegen, wanted_type, actual_type)) { | 8087 | if (types_match_const_cast_only(ira->codegen, wanted_type, actual_type).id == ConstCastResultIdOk) { |
| 8063 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false); | 8088 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false); |
| 8064 | } | 8089 | } |
| 8065 | | 8090 | |
| ... | @@ -8105,7 +8130,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8105,7 +8130,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8105 | TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; | 8130 | TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8106 | assert(ptr_type->id == TypeTableEntryIdPointer); | 8131 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8107 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 8132 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8108 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 8133 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 8109 | { | 8134 | { |
| 8110 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); | 8135 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); |
| 8111 | } | 8136 | } |
| ... | @@ -8123,7 +8148,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8123,7 +8148,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8123 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; | 8148 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; |
| 8124 | | 8149 | |
| 8125 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && | 8150 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && |
| 8126 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type)) | 8151 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type).id == ConstCastResultIdOk) |
| 8127 | { | 8152 | { |
| 8128 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); | 8153 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); |
| 8129 | } | 8154 | } |
| ... | @@ -8139,7 +8164,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8139,7 +8164,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8139 | wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; | 8164 | wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8140 | assert(ptr_type->id == TypeTableEntryIdPointer); | 8165 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8141 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 8166 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8142 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 8167 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 8143 | { | 8168 | { |
| 8144 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); | 8169 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); |
| 8145 | if (type_is_invalid(cast1->value.type)) | 8170 | if (type_is_invalid(cast1->value.type)) |
| ... | @@ -8162,7 +8187,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8162,7 +8187,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8162 | wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; | 8187 | wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8163 | assert(ptr_type->id == TypeTableEntryIdPointer); | 8188 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8164 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 8189 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8165 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 8190 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 8166 | { | 8191 | { |
| 8167 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); | 8192 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 8168 | if (type_is_invalid(cast1->value.type)) | 8193 | if (type_is_invalid(cast1->value.type)) |
| ... | @@ -8224,7 +8249,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8224,7 +8249,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8224 | | 8249 | |
| 8225 | // explicit cast from child type of maybe type to maybe type | 8250 | // explicit cast from child type of maybe type to maybe type |
| 8226 | if (wanted_type->id == TypeTableEntryIdMaybe) { | 8251 | if (wanted_type->id == TypeTableEntryIdMaybe) { |
| 8227 | if (types_match_const_cast_only(ira->codegen, wanted_type->data.maybe.child_type, actual_type)) { | 8252 | if (types_match_const_cast_only(ira->codegen, wanted_type->data.maybe.child_type, actual_type).id == ConstCastResultIdOk) { |
| 8228 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); | 8253 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); |
| 8229 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || | 8254 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || |
| 8230 | actual_type->id == TypeTableEntryIdNumLitFloat) | 8255 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | @@ -8246,7 +8271,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8246,7 +8271,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8246 | | 8271 | |
| 8247 | // explicit cast from child type of error type to error type | 8272 | // explicit cast from child type of error type to error type |
| 8248 | if (wanted_type->id == TypeTableEntryIdErrorUnion) { | 8273 | if (wanted_type->id == TypeTableEntryIdErrorUnion) { |
| 8249 | if (types_match_const_cast_only(ira->codegen, wanted_type->data.error_union.payload_type, actual_type)) { | 8274 | if (types_match_const_cast_only(ira->codegen, wanted_type->data.error_union.payload_type, actual_type).id == ConstCastResultIdOk) { |
| 8250 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); | 8275 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); |
| 8251 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || | 8276 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || |
| 8252 | actual_type->id == TypeTableEntryIdNumLitFloat) | 8277 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | @@ -8268,7 +8293,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8268,7 +8293,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8268 | wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry; | 8293 | wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8269 | assert(ptr_type->id == TypeTableEntryIdPointer); | 8294 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8270 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 8295 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8271 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 8296 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 8272 | { | 8297 | { |
| 8273 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); | 8298 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 8274 | if (type_is_invalid(cast1->value.type)) | 8299 | if (type_is_invalid(cast1->value.type)) |
| ... | @@ -8295,7 +8320,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8295,7 +8320,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8295 | actual_type->id != TypeTableEntryIdMaybe) | 8320 | actual_type->id != TypeTableEntryIdMaybe) |
| 8296 | { | 8321 | { |
| 8297 | TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type; | 8322 | TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type; |
| 8298 | if (types_match_const_cast_only(ira->codegen, wanted_child_type, actual_type) || | 8323 | if (types_match_const_cast_only(ira->codegen, wanted_child_type, actual_type).id == ConstCastResultIdOk || |
| 8299 | actual_type->id == TypeTableEntryIdNullLit || | 8324 | actual_type->id == TypeTableEntryIdNullLit || |
| 8300 | actual_type->id == TypeTableEntryIdNumLitInt || | 8325 | actual_type->id == TypeTableEntryIdNumLitInt || |
| 8301 | actual_type->id == TypeTableEntryIdNumLitFloat) | 8326 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | @@ -8445,7 +8470,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8445,7 +8470,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8445 | // explicit cast from something to const pointer of it | 8470 | // explicit cast from something to const pointer of it |
| 8446 | if (!type_requires_comptime(actual_type)) { | 8471 | if (!type_requires_comptime(actual_type)) { |
| 8447 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); | 8472 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); |
| 8448 | if (types_match_const_cast_only(ira->codegen, wanted_type, const_ptr_actual)) { | 8473 | if (types_match_const_cast_only(ira->codegen, wanted_type, const_ptr_actual).id == ConstCastResultIdOk) { |
| 8449 | return ir_analyze_cast_ref(ira, source_instr, value, wanted_type); | 8474 | return ir_analyze_cast_ref(ira, source_instr, value, wanted_type); |
| 8450 | } | 8475 | } |
| 8451 | } | 8476 | } |
| ... | @@ -8473,7 +8498,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ | ... | @@ -8473,7 +8498,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ |
| 8473 | ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, expected_type, value->value.type, value); | 8498 | ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, expected_type, value->value.type, value); |
| 8474 | switch (result) { | 8499 | switch (result) { |
| 8475 | case ImplicitCastMatchResultNo: | 8500 | case ImplicitCastMatchResultNo: |
| 8476 | ErrorMsg *msg = ir_add_error(ira, value, | 8501 | ir_add_error(ira, value, |
| 8477 | buf_sprintf("expected type '%s', found '%s'", | 8502 | buf_sprintf("expected type '%s', found '%s'", |
| 8478 | buf_ptr(&expected_type->name), | 8503 | buf_ptr(&expected_type->name), |
| 8479 | buf_ptr(&value->value.type->name))); | 8504 | buf_ptr(&value->value.type->name))); |