| author | |
| committer | |
| log | b9f88c3552c0ac892aa6dba7ed8518a0aee51305 |
| tree | 708d70c749f2501ad8b3b57f0870c5ad4ee6a0bc |
| parent | ce96323ba15309c08b868c442ef4511c244e2e83 |
| signature |
2 files changed, 25 insertions(+), 7 deletions(-)
src/ir.cpp+10-4| ... | ... | @@ -12661,21 +12661,27 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 12661 | 12661 | { |
| 12662 | 12662 | Buf *txt_msg = buf_sprintf("destination pointer requires a terminating '"); |
| 12663 | 12663 | render_const_value(ira->codegen, txt_msg, wanted_type->data.pointer.sentinel); |
| 12664 | buf_appendf(txt_msg, "' sentinel value"); | |
| 12664 | buf_appendf(txt_msg, "' sentinel"); | |
| 12665 | 12665 | if (actual_type->data.pointer.sentinel != nullptr) { |
| 12666 | 12666 | buf_appendf(txt_msg, ", but source pointer has a terminating '"); |
| 12667 | 12667 | render_const_value(ira->codegen, txt_msg, actual_type->data.pointer.sentinel); |
| 12668 | buf_appendf(txt_msg, "' sentinel value"); | |
| 12668 | buf_appendf(txt_msg, "' sentinel"); | |
| 12669 | 12669 | } |
| 12670 | 12670 | add_error_note(ira->codegen, parent_msg, source_node, txt_msg); |
| 12671 | 12671 | } |
| 12672 | 12672 | break; |
| 12673 | 12673 | } |
| 12674 | 12674 | case ConstCastResultIdSentinelArrays: { |
| 12675 | ZigType *actual_type = cast_result->data.sentinel_arrays->actual_type; | |
| 12675 | 12676 | ZigType *wanted_type = cast_result->data.sentinel_arrays->wanted_type; |
| 12676 | 12677 | Buf *txt_msg = buf_sprintf("destination array requires a terminating '"); |
| 12677 | render_const_value(ira->codegen, txt_msg, wanted_type->data.pointer.sentinel); | |
| 12678 | buf_appendf(txt_msg, "' sentinel value"); | |
| 12678 | render_const_value(ira->codegen, txt_msg, wanted_type->data.array.sentinel); | |
| 12679 | buf_appendf(txt_msg, "' sentinel"); | |
| 12680 | if (actual_type->data.array.sentinel != nullptr) { | |
| 12681 | buf_appendf(txt_msg, ", but source array has a terminating '"); | |
| 12682 | render_const_value(ira->codegen, txt_msg, actual_type->data.array.sentinel); | |
| 12683 | buf_appendf(txt_msg, "' sentinel"); | |
| 12684 | } | |
| 12679 | 12685 | add_error_note(ira->codegen, parent_msg, source_node, txt_msg); |
| 12680 | 12686 | break; |
| 12681 | 12687 | } |
test/compile_errors.zig+15-3| ... | ... | @@ -3,18 +3,30 @@ const builtin = @import("builtin"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | 5 | cases.add( |
| 6 | "incompatible pointer sentinels", | |
| 6 | "incompatible sentinels", | |
| 7 | 7 | \\export fn entry1(ptr: [*:255]u8) [*:0]u8 { |
| 8 | 8 | \\ return ptr; |
| 9 | 9 | \\} |
| 10 | 10 | \\export fn entry2(ptr: [*]u8) [*:0]u8 { |
| 11 | 11 | \\ return ptr; |
| 12 | 12 | \\} |
| 13 | \\export fn entry3() void { | |
| 14 | \\ var array: [2:0]u8 = [_:255]u8{1, 2}; | |
| 15 | \\} | |
| 16 | \\export fn entry4() void { | |
| 17 | \\ var array: [2:0]u8 = [_]u8{1, 2}; | |
| 18 | \\} | |
| 13 | 19 | , |
| 14 | 20 | "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'", |
| 15 | "tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel value, but source pointer has a terminating '255' sentinel value", | |
| 21 | "tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel", | |
| 16 | 22 | "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'", |
| 17 | "tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel value", | |
| 23 | "tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel", | |
| 24 | ||
| 25 | "tmp.zig:8:35: error: expected type '[2:0]u8', found '[2:255]u8'", | |
| 26 | "tmp.zig:8:35: note: destination array requires a terminating '0' sentinel, but source array has a terminating '255' sentinel", | |
| 27 | "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'", | |
| 28 | "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel", | |
| 29 | ||
| 18 | 30 | ); |
| 19 | 31 | |
| 20 | 32 | cases.add( |