| ... | ... | @@ -183,6 +183,7 @@ struct ConstCastBadCV { |
| 183 | 183 | |
| 184 | 184 | struct ConstCastPtrSentinel { |
| 185 | 185 | ZigType *wanted_type; |
| 186 | ZigType *actual_type; |
| 186 | 187 | }; |
| 187 | 188 | |
| 188 | 189 | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); |
| ... | ... | @@ -9898,7 +9899,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 9898 | 9899 | if (!ok_null_term_ptrs) { |
| 9899 | 9900 | result.id = ConstCastResultIdPtrSentinel; |
| 9900 | 9901 | result.data.bad_ptr_sentinel = allocate_nonzero<ConstCastPtrSentinel>(1); |
| 9901 | | result.data.bad_ptr_sentinel->wanted_type = wanted_type; |
| 9902 | result.data.bad_ptr_sentinel->wanted_type = wanted_ptr_type; |
| 9903 | result.data.bad_ptr_sentinel->actual_type = actual_ptr_type; |
| 9902 | 9904 | return result; |
| 9903 | 9905 | } |
| 9904 | 9906 | bool ptr_lens_equal = actual_ptr_type->data.pointer.ptr_len == wanted_ptr_type->data.pointer.ptr_len; |
| ... | ... | @@ -12653,19 +12655,27 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 12653 | 12655 | break; |
| 12654 | 12656 | } |
| 12655 | 12657 | case ConstCastResultIdPtrSentinel: { |
| 12658 | ZigType *actual_type = cast_result->data.bad_ptr_sentinel->actual_type; |
| 12656 | 12659 | ZigType *wanted_type = cast_result->data.bad_ptr_sentinel->wanted_type; |
| 12657 | | Buf *msg = buf_sprintf("destination pointer requires a terminating '"); |
| 12658 | | render_const_value(ira->codegen, msg, wanted_type->data.pointer.sentinel); |
| 12659 | | buf_appendf(msg, "' sentinel value"); |
| 12660 | | add_error_note(ira->codegen, parent_msg, source_node, msg); |
| 12660 | { |
| 12661 | Buf *txt_msg = buf_sprintf("destination pointer requires a terminating '"); |
| 12662 | render_const_value(ira->codegen, txt_msg, wanted_type->data.pointer.sentinel); |
| 12663 | buf_appendf(txt_msg, "' sentinel value"); |
| 12664 | if (actual_type->data.pointer.sentinel != nullptr) { |
| 12665 | buf_appendf(txt_msg, ", but source pointer has a terminating '"); |
| 12666 | render_const_value(ira->codegen, txt_msg, actual_type->data.pointer.sentinel); |
| 12667 | buf_appendf(txt_msg, "' sentinel value"); |
| 12668 | } |
| 12669 | add_error_note(ira->codegen, parent_msg, source_node, txt_msg); |
| 12670 | } |
| 12661 | 12671 | break; |
| 12662 | 12672 | } |
| 12663 | 12673 | case ConstCastResultIdSentinelArrays: { |
| 12664 | 12674 | ZigType *wanted_type = cast_result->data.sentinel_arrays->wanted_type; |
| 12665 | | Buf *msg = buf_sprintf("destination array requires a terminating '"); |
| 12666 | | render_const_value(ira->codegen, msg, wanted_type->data.pointer.sentinel); |
| 12667 | | buf_appendf(msg, "' sentinel value"); |
| 12668 | | add_error_note(ira->codegen, parent_msg, source_node, msg); |
| 12675 | Buf *txt_msg = buf_sprintf("destination array requires a terminating '"); |
| 12676 | render_const_value(ira->codegen, txt_msg, wanted_type->data.pointer.sentinel); |
| 12677 | buf_appendf(txt_msg, "' sentinel value"); |
| 12678 | add_error_note(ira->codegen, parent_msg, source_node, txt_msg); |
| 12669 | 12679 | break; |
| 12670 | 12680 | } |
| 12671 | 12681 | case ConstCastResultIdCV: { |