From 278db0ad4543d7a768c63c5482b8873b58690920 Mon Sep 17 00:00:00 2001 From: Carl Ã…stholm Date: Tue, 13 Feb 2024 22:30:14 +0100 Subject: Sema: support coercing ref to anonymous array init to many-pointer --- test/behavior/array.zig | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'test/behavior/array.zig') 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 = &.{ -- cgit v1.2.3