add compile error for @ptrCast 0 bit type to non-0 bit type

This commit is contained in:
Andrew Kelley
2018-09-17 19:41:11 -04:00
parent 78a9a465a3
commit b16229da1d
2 changed files with 30 additions and 3 deletions

View File

@@ -1,6 +1,19 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"@ptrCast a 0 bit type to a non- 0 bit type",
\\export fn entry() bool {
\\ var x: u0 = 0;
\\ const p = @ptrCast(?*u0, &x);
\\ return p == null;
\\}
,
".tmp_source.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation",
".tmp_source.zig:3:31: note: '*u0' has no in-memory bits",
".tmp_source.zig:3:24: note: '?*u0' has in-memory bits",
);
cases.add(
"comparing a non-optional pointer against null",
\\export fn entry() void {