add compile error for incompatible pointer sentinels

This commit is contained in:
Andrew Kelley
2019-11-24 17:02:56 -05:00
parent 4018034708
commit c96d565166
2 changed files with 34 additions and 9 deletions

View File

@@ -2,6 +2,21 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"incompatible pointer sentinels",
\\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
\\ return ptr;
\\}
\\export fn entry2(ptr: [*]u8) [*:0]u8 {
\\ return ptr;
\\}
,
"tmp.zig:2:5: error: expected type '[*:0]u8', found '[*:255]u8'",
"tmp.zig:2:5: note: destination pointer requires a terminating '0' sentinel value, but source pointer has a terminating '255' sentinel value",
"tmp.zig:5:5: error: expected type '[*:0]u8', found '[*]u8'",
"tmp.zig:5:5: note: destination pointer requires a terminating '0' sentinel value",
);
cases.add(
"regression test #2980: base type u32 is not type checked properly when assigning a value within a struct",
\\const Foo = struct {