mirror of
https://github.com/ziglang/zig.git
synced 2026-01-06 05:25:10 +00:00
fix compile errors for array sentinels mismatching
This commit is contained in:
parent
ce96323ba1
commit
b9f88c3552
14
src/ir.cpp
14
src/ir.cpp
@ -12661,21 +12661,27 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
|
||||
{
|
||||
Buf *txt_msg = buf_sprintf("destination pointer requires a terminating '");
|
||||
render_const_value(ira->codegen, txt_msg, wanted_type->data.pointer.sentinel);
|
||||
buf_appendf(txt_msg, "' sentinel value");
|
||||
buf_appendf(txt_msg, "' sentinel");
|
||||
if (actual_type->data.pointer.sentinel != nullptr) {
|
||||
buf_appendf(txt_msg, ", but source pointer has a terminating '");
|
||||
render_const_value(ira->codegen, txt_msg, actual_type->data.pointer.sentinel);
|
||||
buf_appendf(txt_msg, "' sentinel value");
|
||||
buf_appendf(txt_msg, "' sentinel");
|
||||
}
|
||||
add_error_note(ira->codegen, parent_msg, source_node, txt_msg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ConstCastResultIdSentinelArrays: {
|
||||
ZigType *actual_type = cast_result->data.sentinel_arrays->actual_type;
|
||||
ZigType *wanted_type = cast_result->data.sentinel_arrays->wanted_type;
|
||||
Buf *txt_msg = buf_sprintf("destination array requires a terminating '");
|
||||
render_const_value(ira->codegen, txt_msg, wanted_type->data.pointer.sentinel);
|
||||
buf_appendf(txt_msg, "' sentinel value");
|
||||
render_const_value(ira->codegen, txt_msg, wanted_type->data.array.sentinel);
|
||||
buf_appendf(txt_msg, "' sentinel");
|
||||
if (actual_type->data.array.sentinel != nullptr) {
|
||||
buf_appendf(txt_msg, ", but source array has a terminating '");
|
||||
render_const_value(ira->codegen, txt_msg, actual_type->data.array.sentinel);
|
||||
buf_appendf(txt_msg, "' sentinel");
|
||||
}
|
||||
add_error_note(ira->codegen, parent_msg, source_node, txt_msg);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3,18 +3,30 @@ const builtin = @import("builtin");
|
||||
|
||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
cases.add(
|
||||
"incompatible pointer sentinels",
|
||||
"incompatible sentinels",
|
||||
\\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
|
||||
\\ return ptr;
|
||||
\\}
|
||||
\\export fn entry2(ptr: [*]u8) [*:0]u8 {
|
||||
\\ return ptr;
|
||||
\\}
|
||||
\\export fn entry3() void {
|
||||
\\ var array: [2:0]u8 = [_:255]u8{1, 2};
|
||||
\\}
|
||||
\\export fn entry4() void {
|
||||
\\ var array: [2:0]u8 = [_]u8{1, 2};
|
||||
\\}
|
||||
,
|
||||
"tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'",
|
||||
"tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel value, but source pointer has a terminating '255' sentinel value",
|
||||
"tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel",
|
||||
"tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",
|
||||
"tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel value",
|
||||
"tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel",
|
||||
|
||||
"tmp.zig:8:35: error: expected type '[2:0]u8', found '[2:255]u8'",
|
||||
"tmp.zig:8:35: note: destination array requires a terminating '0' sentinel, but source array has a terminating '255' sentinel",
|
||||
"tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'",
|
||||
"tmp.zig:11:31: note: destination array requires a terminating '0' sentinel",
|
||||
|
||||
);
|
||||
|
||||
cases.add(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user