diff options
| author | InKryption <inkryption07@gmail.com> | 2023-03-16 01:02:10 +0100 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-03-16 13:00:36 +0200 |
| commit | 9964f1c160acd0bf994708333cd69bc070d6c77e (patch) | |
| tree | 95038ad8fe5011ad7df08a567e8c3bc545c3532e /test/cases/compile_errors | |
| parent | e1e414e62a86cc460ef215ea8050c953b68b6080 (diff) | |
| download | zig-9964f1c160acd0bf994708333cd69bc070d6c77e.tar.gz zig-9964f1c160acd0bf994708333cd69bc070d6c77e.zip | |
Add error for bad cast from `*T` to `*[n]T`
Casting `*T` to `*[1]T` should still work, but every other length
will now be a compiler error instead of a potential OOB access.
Diffstat (limited to 'test/cases/compile_errors')
| -rw-r--r-- | test/cases/compile_errors/attempted_implicit_cast_from_T_to_long_array_ptr.zig | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/cases/compile_errors/attempted_implicit_cast_from_T_to_long_array_ptr.zig b/test/cases/compile_errors/attempted_implicit_cast_from_T_to_long_array_ptr.zig new file mode 100644 index 0000000000..135081c15c --- /dev/null +++ b/test/cases/compile_errors/attempted_implicit_cast_from_T_to_long_array_ptr.zig @@ -0,0 +1,18 @@ +export fn entry0(single: *u32) void { + _ = @as(*const [0]u32, single); +} +export fn entry1(single: *u32) void { + _ = @as(*const [1]u32, single); +} +export fn entry2(single: *u32) void { + _ = @as(*const [2]u32, single); +} + +// error +// backend=stage2 +// target=native +// +// :2:28: error: expected type '*const [0]u32', found '*u32' +// :2:28: note: pointer type child 'u32' cannot cast into pointer type child '[0]u32' +// :8:28: error: expected type '*const [2]u32', found '*u32' +// :8:28: note: pointer type child 'u32' cannot cast into pointer type child '[2]u32' |
