aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/array.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-09-21 01:49:28 -0700
committerGitHub <noreply@github.com>2025-09-21 01:49:28 -0700
commit010d9a63f20d8a4bd14cff0ada690b2d127a0371 (patch)
tree12b56ddfe5a5b235ef0676832902a0b04ad7d57a /test/behavior/array.zig
parent3fbb88c4bd146ca7bd9e7ab5da9c4b05298f3b34 (diff)
parent633162eb0c8d302ba7585cd308e01237409f042e (diff)
downloadzig-010d9a63f20d8a4bd14cff0ada690b2d127a0371.tar.gz
zig-010d9a63f20d8a4bd14cff0ada690b2d127a0371.zip
Merge pull request #25154 from ziglang/no-decl-val-3
rework byval ZIR instructions; forbid runtime vector indexes
Diffstat (limited to 'test/behavior/array.zig')
-rw-r--r--test/behavior/array.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig
index 741e9505b0..b28ee267c2 100644
--- a/test/behavior/array.zig
+++ b/test/behavior/array.zig
@@ -1125,3 +1125,24 @@ test "splat with an error union or optional result type" {
_ = try S.doTest(@Vector(4, u32));
_ = try S.doTest([4]u32);
}
+
+test "resist alias of explicit copy of array passed as arg" {
+ const S = struct {
+ const Thing = [1]u32;
+
+ fn destroy_and_replace(box_b: *Thing, a: Thing, box_a: *Thing) void {
+ box_a.* = undefined;
+ box_b.* = a;
+ }
+ };
+
+ var buf_a: S.Thing = .{1234};
+ var buf_b: S.Thing = .{5678};
+ const box_a = &buf_a;
+ const box_b = &buf_b;
+
+ const a = box_a.*; // explicit copy
+ S.destroy_and_replace(box_b, a, box_a);
+
+ try expect(buf_b[0] == 1234);
+}