aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/vector.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-06-07 10:20:34 +0100
committerAndrew Kelley <andrew@ziglang.org>2023-06-14 22:07:25 -0700
commitce88c43a4ee94d82a64e7580885dc6693cc6120c (patch)
tree2ec2dd9966ff2f96186d13872031c074a81e50bc /test/behavior/vector.zig
parent610b02c432072c85f079f3ddf315cb864aa5dbf5 (diff)
downloadzig-ce88c43a4ee94d82a64e7580885dc6693cc6120c.tar.gz
zig-ce88c43a4ee94d82a64e7580885dc6693cc6120c.zip
Sema: allow indexing tuple and vector pointers
Resolves: #13852 Resolves: #14705
Diffstat (limited to 'test/behavior/vector.zig')
-rw-r--r--test/behavior/vector.zig27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig
index 195500c178..367a21fc0a 100644
--- a/test/behavior/vector.zig
+++ b/test/behavior/vector.zig
@@ -2,6 +2,7 @@ const std = @import("std");
const builtin = @import("builtin");
const mem = std.mem;
const math = std.math;
+const assert = std.debug.assert;
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
@@ -1343,3 +1344,29 @@ test "compare vectors with different element types" {
var b: @Vector(2, u9) = .{ 3, 0 };
try expectEqual(@Vector(2, bool){ true, false }, a < b);
}
+
+test "vector pointer is indexable" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO
+
+ const V = @Vector(2, u32);
+
+ const x: V = .{ 123, 456 };
+ comptime assert(@TypeOf(&(&x)[0]) == *const u32); // validate constness
+ try expectEqual(@as(u32, 123), (&x)[0]);
+ try expectEqual(@as(u32, 456), (&x)[1]);
+
+ var y: V = .{ 123, 456 };
+ comptime assert(@TypeOf(&(&y)[0]) == *u32); // validate constness
+ try expectEqual(@as(u32, 123), (&y)[0]);
+ try expectEqual(@as(u32, 456), (&y)[1]);
+
+ (&y)[0] = 100;
+ (&y)[1] = 200;
+ try expectEqual(@as(u32, 100), (&y)[0]);
+ try expectEqual(@as(u32, 200), (&y)[1]);
+}