| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | const assert = std.debug.assert; |
| 3 | 4 | const expect = std.testing.expect; |
| 4 | 5 | const expectEqual = std.testing.expectEqual; |
| 5 | 6 | |
| ... | ... | @@ -830,3 +831,23 @@ test "const type-annotated local initialized with function call has correct type |
| 830 | 831 | try expect(@TypeOf(x) == u64); |
| 831 | 832 | try expect(x == 1234); |
| 832 | 833 | } |
| 834 | |
| 835 | test "comptime pointer load through elem_ptr" { |
| 836 | const S = struct { |
| 837 | x: usize, |
| 838 | }; |
| 839 | |
| 840 | comptime { |
| 841 | var array: [10]S = undefined; |
| 842 | for (array) |*elem, i| { |
| 843 | elem.* = .{ |
| 844 | .x = i, |
| 845 | }; |
| 846 | } |
| 847 | var ptr = @ptrCast([*]S, &array); |
| 848 | var x = ptr[0].x; |
| 849 | assert(x == 0); |
| 850 | ptr += 1; |
| 851 | assert(ptr[1].x == 2); |
| 852 | } |
| 853 | } |