aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/tuple.zig
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2021-06-06 12:26:15 +0200
committerAndrew Kelley <andrew@ziglang.org>2021-06-06 21:21:42 -0400
commitfc8791c133c14fe969b9056d8f0e337094ce1461 (patch)
tree2748fac999f47ea06ba9a892ae3734ca69ace042 /test/behavior/tuple.zig
parentb87c3d5371a277a60e63dc521a44d488f013dbc8 (diff)
downloadzig-fc8791c133c14fe969b9056d8f0e337094ce1461.tar.gz
zig-fc8791c133c14fe969b9056d8f0e337094ce1461.zip
stage1: Allow array-like initialization for tuple types
This small change makes working with tuple types much easier, allowing the use of anonymous (eg. obtained with meta.ArgsTuple) tuples in more places without the need for specifying each (quoted!) field name in the initializer.
Diffstat (limited to 'test/behavior/tuple.zig')
-rw-r--r--test/behavior/tuple.zig36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/behavior/tuple.zig b/test/behavior/tuple.zig
index 0a32c664dd..29d44d582f 100644
--- a/test/behavior/tuple.zig
+++ b/test/behavior/tuple.zig
@@ -111,3 +111,39 @@ test "tuple initializer for var" {
S.doTheTest();
comptime S.doTheTest();
}
+
+test "array-like initializer for tuple types" {
+ const T = @Type(std.builtin.TypeInfo{
+ .Struct = std.builtin.TypeInfo.Struct{
+ .is_tuple = true,
+ .layout = .Auto,
+ .decls = &[_]std.builtin.TypeInfo.Declaration{},
+ .fields = &[_]std.builtin.TypeInfo.StructField{
+ .{
+ .name = "0",
+ .field_type = i32,
+ .default_value = @as(?i32, null),
+ .is_comptime = false,
+ .alignment = @alignOf(i32),
+ },
+ .{
+ .name = "1",
+ .field_type = u8,
+ .default_value = @as(?i32, null),
+ .is_comptime = false,
+ .alignment = @alignOf(i32),
+ },
+ },
+ },
+ });
+ const S = struct {
+ fn doTheTest() !void {
+ var obj: T = .{ -1234, 128 };
+ try testing.expectEqual(@as(i32, -1234), obj[0]);
+ try testing.expectEqual(@as(u8, 128), obj[1]);
+ }
+ };
+
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}