| ... | ... | @@ -82,6 +82,7 @@ struct ConstCastSliceMismatch; |
| 82 | 82 | struct ConstCastErrUnionErrSetMismatch; |
| 83 | 83 | struct ConstCastErrUnionPayloadMismatch; |
| 84 | 84 | struct ConstCastErrSetMismatch; |
| 85 | struct ConstCastTypeMismatch; |
| 85 | 86 | |
| 86 | 87 | struct ConstCastOnly { |
| 87 | 88 | ConstCastResultId id; |
| ... | ... | @@ -92,6 +93,7 @@ struct ConstCastOnly { |
| 92 | 93 | ConstCastOptionalMismatch *optional; |
| 93 | 94 | ConstCastErrUnionPayloadMismatch *error_union_payload; |
| 94 | 95 | ConstCastErrUnionErrSetMismatch *error_union_error_set; |
| 96 | ConstCastTypeMismatch *type_mismatch; |
| 95 | 97 | ConstCastOnly *return_type; |
| 96 | 98 | ConstCastOnly *async_allocator_type; |
| 97 | 99 | ConstCastOnly *null_wrap_ptr_child; |
| ... | ... | @@ -100,6 +102,11 @@ struct ConstCastOnly { |
| 100 | 102 | } data; |
| 101 | 103 | }; |
| 102 | 104 | |
| 105 | struct ConstCastTypeMismatch { |
| 106 | TypeTableEntry *wanted_type; |
| 107 | TypeTableEntry *actual_type; |
| 108 | }; |
| 109 | |
| 103 | 110 | struct ConstCastOptionalMismatch { |
| 104 | 111 | ConstCastOnly child; |
| 105 | 112 | TypeTableEntry *wanted_child; |
| ... | ... | @@ -8128,15 +8135,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8128 | 8135 | } |
| 8129 | 8136 | |
| 8130 | 8137 | // pointer const |
| 8131 | | if (wanted_type->id == TypeTableEntryIdPointer && |
| 8132 | | actual_type->id == TypeTableEntryIdPointer && |
| 8133 | | (actual_type->data.pointer.ptr_len == wanted_type->data.pointer.ptr_len) && |
| 8134 | | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && |
| 8135 | | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile) && |
| 8136 | | actual_type->data.pointer.bit_offset == wanted_type->data.pointer.bit_offset && |
| 8137 | | actual_type->data.pointer.unaligned_bit_count == wanted_type->data.pointer.unaligned_bit_count && |
| 8138 | | actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment) |
| 8139 | | { |
| 8138 | if (wanted_type->id == TypeTableEntryIdPointer && actual_type->id == TypeTableEntryIdPointer) { |
| 8140 | 8139 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 8141 | 8140 | actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const); |
| 8142 | 8141 | if (child.id != ConstCastResultIdOk) { |
| ... | ... | @@ -8145,8 +8144,17 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8145 | 8144 | result.data.pointer_mismatch->child = child; |
| 8146 | 8145 | result.data.pointer_mismatch->wanted_child = wanted_type->data.pointer.child_type; |
| 8147 | 8146 | result.data.pointer_mismatch->actual_child = actual_type->data.pointer.child_type; |
| 8147 | return result; |
| 8148 | } |
| 8149 | if ((actual_type->data.pointer.ptr_len == wanted_type->data.pointer.ptr_len) && |
| 8150 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && |
| 8151 | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile) && |
| 8152 | actual_type->data.pointer.bit_offset == wanted_type->data.pointer.bit_offset && |
| 8153 | actual_type->data.pointer.unaligned_bit_count == wanted_type->data.pointer.unaligned_bit_count && |
| 8154 | actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment) |
| 8155 | { |
| 8156 | return result; |
| 8148 | 8157 | } |
| 8149 | | return result; |
| 8150 | 8158 | } |
| 8151 | 8159 | |
| 8152 | 8160 | // slice const |
| ... | ... | @@ -8341,6 +8349,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8341 | 8349 | } |
| 8342 | 8350 | |
| 8343 | 8351 | result.id = ConstCastResultIdType; |
| 8352 | result.data.type_mismatch = allocate_nonzero<ConstCastTypeMismatch>(1); |
| 8353 | result.data.type_mismatch->wanted_type = wanted_type; |
| 8354 | result.data.type_mismatch->actual_type = actual_type; |
| 8344 | 8355 | return result; |
| 8345 | 8356 | } |
| 8346 | 8357 | |
| ... | ... | @@ -10154,6 +10165,21 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 10154 | 10165 | report_recursive_error(ira, source_node, &cast_result->data.error_union_payload->child, msg); |
| 10155 | 10166 | break; |
| 10156 | 10167 | } |
| 10168 | case ConstCastResultIdType: { |
| 10169 | AstNode *wanted_decl_node = type_decl_node(cast_result->data.type_mismatch->wanted_type); |
| 10170 | AstNode *actual_decl_node = type_decl_node(cast_result->data.type_mismatch->actual_type); |
| 10171 | if (wanted_decl_node != nullptr) { |
| 10172 | add_error_note(ira->codegen, parent_msg, wanted_decl_node, |
| 10173 | buf_sprintf("%s declared here", |
| 10174 | buf_ptr(&cast_result->data.type_mismatch->wanted_type->name))); |
| 10175 | } |
| 10176 | if (actual_decl_node != nullptr) { |
| 10177 | add_error_note(ira->codegen, parent_msg, actual_decl_node, |
| 10178 | buf_sprintf("%s declared here", |
| 10179 | buf_ptr(&cast_result->data.type_mismatch->actual_type->name))); |
| 10180 | } |
| 10181 | break; |
| 10182 | } |
| 10157 | 10183 | case ConstCastResultIdFnAlign: // TODO |
| 10158 | 10184 | case ConstCastResultIdFnCC: // TODO |
| 10159 | 10185 | case ConstCastResultIdFnVarArgs: // TODO |
| ... | ... | @@ -10163,7 +10189,6 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 10163 | 10189 | case ConstCastResultIdFnGenericArgCount: // TODO |
| 10164 | 10190 | case ConstCastResultIdFnArg: // TODO |
| 10165 | 10191 | case ConstCastResultIdFnArgNoAlias: // TODO |
| 10166 | | case ConstCastResultIdType: // TODO |
| 10167 | 10192 | case ConstCastResultIdUnresolvedInferredErrSet: // TODO |
| 10168 | 10193 | case ConstCastResultIdAsyncAllocatorType: // TODO |
| 10169 | 10194 | case ConstCastResultIdNullWrapPtr: // TODO |