Fix lvalue dereference type checking

Previously, if a dereference instruction was an lvalue, it would fail to
typecheck that the value being dereferenced was indeed a pointer.
Although a little clunky, this change obviates the need for redundant
type checks scattered about the analysis.
This commit is contained in:
Matthew McAllister
2019-02-12 21:22:16 -08:00
parent c3c92ca8b1
commit 91989e70ba
3 changed files with 45 additions and 29 deletions

View File

@@ -137,6 +137,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
".tmp_source.zig:3:15: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'",
);
cases.addTest(
"assign to invalid dereference",
\\export fn entry() void {
\\ 'a'.* = 1;
\\}
,
".tmp_source.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'",
);
cases.addTest(
"take slice of invalid dereference",
\\export fn entry() void {
\\ const x = 'a'.*[0..];
\\}
,
".tmp_source.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'",
);
cases.addTest(
"@truncate undefined value",
\\export fn entry() void {
@@ -447,7 +465,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ _ = a.*.len;
\\}
,
".tmp_source.zig:3:12: error: attempt to dereference non-pointer type '[]u8'",
".tmp_source.zig:3:10: error: attempt to dereference non-pointer type '[]u8'",
);
cases.add(
@@ -1158,7 +1176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ Filled,
\\};
,
".tmp_source.zig:3:17: error: invalid deref on switch target",
".tmp_source.zig:3:17: error: attempt to dereference non-pointer type 'Tile'",
);
cases.add(
@@ -4000,7 +4018,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\
\\export fn entry() usize { return @sizeOf(@typeOf(pass)); }
,
".tmp_source.zig:4:10: error: attempt to dereference non pointer type '[10]u8'",
".tmp_source.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'",
);
cases.add(