diff options
| author | Carl Ã…stholm <carl@astholm.se> | 2024-02-13 22:30:14 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-04-07 15:10:49 -0700 |
| commit | 278db0ad4543d7a768c63c5482b8873b58690920 (patch) | |
| tree | 74dae2e3443bc7018ff2878f08a1c6e475931cfe /test/behavior/array.zig | |
| parent | fdd6c31e8b25f9eed81c1e78fa71eca17fd29f68 (diff) | |
| download | zig-278db0ad4543d7a768c63c5482b8873b58690920.tar.gz zig-278db0ad4543d7a768c63c5482b8873b58690920.zip | |
Sema: support coercing ref to anonymous array init to many-pointer
Diffstat (limited to 'test/behavior/array.zig')
| -rw-r--r-- | test/behavior/array.zig | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig index a56e382821..6397094398 100644 --- a/test/behavior/array.zig +++ b/test/behavior/array.zig @@ -804,6 +804,52 @@ test "slice initialized through reference to anonymous array init provides resul try std.testing.expectEqualSlices(u16, &.{ 123, 456, 123, 456 }, foo); } +test "sentinel-terminated slice initialized through reference to anonymous array init provides result types" { + var my_u32: u32 = 123; + var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; + const foo: [:999]const u16 = &.{ + @intCast(my_u32), + @intCast(my_u64), + @truncate(my_u32), + @truncate(my_u64), + }; + try std.testing.expectEqualSentinel(u16, 999, &.{ 123, 456, 123, 456 }, foo); +} + +test "many-item pointer initialized through reference to anonymous array init provides result types" { + var my_u32: u32 = 123; + var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; + const foo: [*]const u16 = &.{ + @intCast(my_u32), + @intCast(my_u64), + @truncate(my_u32), + @truncate(my_u64), + }; + try expectEqual(123, foo[0]); + try expectEqual(456, foo[1]); + try expectEqual(123, foo[2]); + try expectEqual(456, foo[3]); +} + +test "many-item sentinel-terminated pointer initialized through reference to anonymous array init provides result types" { + var my_u32: u32 = 123; + var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; + const foo: [*:999]const u16 = &.{ + @intCast(my_u32), + @intCast(my_u64), + @truncate(my_u32), + @truncate(my_u64), + }; + try expectEqual(123, foo[0]); + try expectEqual(456, foo[1]); + try expectEqual(123, foo[2]); + try expectEqual(456, foo[3]); + try expectEqual(999, foo[4]); +} + test "pointer to array initialized through reference to anonymous array init provides result types" { var my_u32: u32 = 123; var my_u64: u64 = 456; @@ -817,6 +863,19 @@ test "pointer to array initialized through reference to anonymous array init pro try std.testing.expectEqualSlices(u16, &.{ 123, 456, 123, 456 }, foo); } +test "pointer to sentinel-terminated array initialized through reference to anonymous array init provides result types" { + var my_u32: u32 = 123; + var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; + const foo: *const [4:999]u16 = &.{ + @intCast(my_u32), + @intCast(my_u64), + @truncate(my_u32), + @truncate(my_u64), + }; + try std.testing.expectEqualSentinel(u16, 999, &.{ 123, 456, 123, 456 }, foo); +} + test "tuple initialized through reference to anonymous array init provides result types" { const Tuple = struct { u64, *const u32 }; const foo: *const Tuple = &.{ |
