aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/tuple.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/tuple.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/tuple.zig')
-rw-r--r--test/behavior/tuple.zig25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/behavior/tuple.zig b/test/behavior/tuple.zig
index 190ac3c7df..ee414365c3 100644
--- a/test/behavior/tuple.zig
+++ b/test/behavior/tuple.zig
@@ -1,6 +1,7 @@
const builtin = @import("builtin");
const std = @import("std");
const testing = std.testing;
+const assert = std.debug.assert;
const expect = testing.expect;
const expectEqualStrings = std.testing.expectEqualStrings;
const expectEqual = std.testing.expectEqual;
@@ -428,3 +429,27 @@ test "sentinel slice in tuple" {
_ = S;
}
+
+test "tuple 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_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO
+
+ const S = struct { u32, bool };
+
+ const x: S = .{ 123, true };
+ comptime assert(@TypeOf(&(&x)[0]) == *const u32); // validate constness
+ try expectEqual(@as(u32, 123), (&x)[0]);
+ try expectEqual(true, (&x)[1]);
+
+ var y: S = .{ 123, true };
+ comptime assert(@TypeOf(&(&y)[0]) == *u32); // validate constness
+ try expectEqual(@as(u32, 123), (&y)[0]);
+ try expectEqual(true, (&y)[1]);
+
+ (&y)[0] = 100;
+ (&y)[1] = false;
+ try expectEqual(@as(u32, 100), (&y)[0]);
+ try expectEqual(false, (&y)[1]);
+}