authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-23 13:46:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-23 13:46:06-07:00
log41e300adf17bc4056c574b32de4e07f129f2bd24
tree8af430e781e1913c13dbdf5a158e457a03dd965d
parent5374e245c50fde8bbb133bbff2db15efa3604721

add behavior test to cover bug fix in previous commit


1 files changed, 21 insertions(+), 0 deletions(-)

test/behavior/eval.zig+21
......@@ -1,5 +1,6 @@
11const builtin = @import("builtin");
22const std = @import("std");
3const assert = std.debug.assert;
34const expect = std.testing.expect;
45const expectEqual = std.testing.expectEqual;
56
......@@ -830,3 +831,23 @@ test "const type-annotated local initialized with function call has correct type
830831 try expect(@TypeOf(x) == u64);
831832 try expect(x == 1234);
832833}
834
835test "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}