authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-02-05 19:53:12+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-02-05 19:53:12+00:00
logfbe0ae4fd4128a3652071b4b5985d68ae56e9992
treea122df94fa0b93d6c0b4c28bf5d5ae9d9385d282
parent0f38558435a0f73c4c025b5641bd8e531f063e0c
signaturelock-open Commit is signed but in an unrecognized format.

Sema: fix PTR of slice of sentinel-terminated array

Resolves: #20901

2 files changed, 18 insertions(+), 2 deletions(-)

src/Sema.zig+2-2
...@@ -34603,14 +34603,14 @@ fn resolvePeerTypesInner(...@@ -34603,14 +34603,14 @@ fn resolvePeerTypesInner(
34603 }34603 }
34604 // Clear existing sentinel34604 // Clear existing sentinel
34605 ptr_info.sentinel = .none;34605 ptr_info.sentinel = .none;
34606 switch (ip.indexToKey(ptr_info.child)) {34606 if (ptr_info.flags.size == .one) switch (ip.indexToKey(ptr_info.child)) {
34607 .array_type => |array_type| ptr_info.child = (try pt.arrayType(.{34607 .array_type => |array_type| ptr_info.child = (try pt.arrayType(.{
34608 .len = array_type.len,34608 .len = array_type.len,
34609 .child = array_type.child,34609 .child = array_type.child,
34610 .sentinel = .none,34610 .sentinel = .none,
34611 })).toIntern(),34611 })).toIntern(),
34612 else => {},34612 else => {},
34613 }34613 };
34614 }34614 }
3461534615
34616 opt_ptr_info = ptr_info;34616 opt_ptr_info = ptr_info;
test/behavior/cast.zig+16
...@@ -2649,3 +2649,19 @@ test "bitcast vector" {...@@ -2649,3 +2649,19 @@ test "bitcast vector" {
2649 const bigsum: u32x8 = @bitCast(zerox32);2649 const bigsum: u32x8 = @bitCast(zerox32);
2650 try std.testing.expectEqual(0, @reduce(.Add, bigsum));2650 try std.testing.expectEqual(0, @reduce(.Add, bigsum));
2651}2651}
2652
2653test "peer type resolution: slice of sentinel-terminated array" {
2654 var f: bool = undefined;
2655 f = false;
2656
2657 const a: [][2:0]u8 = &.{};
2658 const b: []const [2:0]u8 = &.{.{ 10, 20 }};
2659
2660 const result = if (f) a else b;
2661
2662 comptime assert(@TypeOf(result) == []const [2:0]u8);
2663 try expect(result.len == 1);
2664 try expect(result[0].len == 2);
2665 try expect(result[0][0] == 10);
2666 try expect(result[0][1] == 20);
2667}