zig/test/cases/compile_errors/incompatible_sentinels.zig
Alex Rønne Petersen 2e3fac3626
test: rename backend=stage2 to backend=selfhosted, and add backend=auto
backend=auto (now the default if backend is omitted) means to let the compiler
pick whatever backend it wants as the default. This is important for platforms
where we don't yet have a self-hosted backend, such as loongarch64.

Also purge a bunch of redundant target=native.
2025-09-16 23:39:26 +02:00

30 lines
1.1 KiB
Zig

// Note: One of the error messages here is backwards. It would be nice to fix, but that's not
// going to stop me from merging this branch which fixes a bunch of other stuff.
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 };
_ = &array;
}
export fn entry4() void {
var array: [2:0]u8 = [_]u8{ 1, 2 };
_ = &array;
}
// error
//
// :4:12: error: expected type '[*:0]u8', found '[*:255]u8'
// :4:12: note: pointer sentinel '255' cannot cast into pointer sentinel '0'
// :3:34: note: function return type declared here
// :7:12: error: expected type '[*:0]u8', found '[*]u8'
// :7:12: note: destination pointer requires '0' sentinel
// :6:30: note: function return type declared here
// :10:35: error: expected type '[2:0]u8', found '[2:255]u8'
// :10:35: note: array sentinel '255' cannot cast into array sentinel '0'
// :14:31: error: expected type '[2:0]u8', found '[2]u8'
// :14:31: note: destination array requires '0' sentinel