diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-03-23 16:46:50 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-23 16:46:50 -0400 |
| commit | a2b0b0015d8a0c7aff451ae723ed2f30360ca33f (patch) | |
| tree | 8af430e781e1913c13dbdf5a158e457a03dd965d /test/behavior/eval.zig | |
| parent | b872539a13ac46abe57a59bafdf5392812468482 (diff) | |
| parent | 41e300adf17bc4056c574b32de4e07f129f2bd24 (diff) | |
| download | zig-a2b0b0015d8a0c7aff451ae723ed2f30360ca33f.tar.gz zig-a2b0b0015d8a0c7aff451ae723ed2f30360ca33f.zip | |
Merge pull request #11273 from topolarity/bugfix-11272
stage2: Properly "flatten" elem_ptrs before deref
Diffstat (limited to 'test/behavior/eval.zig')
| -rw-r--r-- | test/behavior/eval.zig | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/behavior/eval.zig b/test/behavior/eval.zig index 03a7a511f0..c4c6f47981 100644 --- a/test/behavior/eval.zig +++ b/test/behavior/eval.zig @@ -1,5 +1,6 @@ const builtin = @import("builtin"); const std = @import("std"); +const assert = std.debug.assert; const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; @@ -830,3 +831,23 @@ test "const type-annotated local initialized with function call has correct type try expect(@TypeOf(x) == u64); try expect(x == 1234); } + +test "comptime pointer load through elem_ptr" { + const S = struct { + x: usize, + }; + + comptime { + var array: [10]S = undefined; + for (array) |*elem, i| { + elem.* = .{ + .x = i, + }; + } + var ptr = @ptrCast([*]S, &array); + var x = ptr[0].x; + assert(x == 0); + ptr += 1; + assert(ptr[1].x == 2); + } +} |
