authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-10-21 16:07:51+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-23 02:16:37+02:00
loga4695d4db91763b5aabe15c8cc4c906325815d50
treedd10c0a3d4a1a68411de47967d48c010815a3783
parent5382c84ed22519a600642f5cf3b1d8c2769050d6
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Sema: fix coercion from untyped `&.{}` to empty slice

We weren't resolving the type before creating the value, which was causing a crash in the LLVM backend. Resolves: https://codeberg.org/ziglang/zig/issues/37155

2 files changed, 21 insertions(+), 0 deletions(-)

src/Sema.zig+1
...@@ -28452,6 +28452,7 @@ fn coerceExtra(...@@ -28452,6 +28452,7 @@ fn coerceExtra(
28452 .child = dest_info.child,28452 .child = dest_info.child,
28453 .sentinel = dest_info.sentinel,28453 .sentinel = dest_info.sentinel,
28454 });28454 });
28455 try sema.ensureLayoutResolved(empty_array_ty, inst_src, .init);
28455 const empty_array_val = try pt.aggregateValue(empty_array_ty, &.{});28456 const empty_array_val = try pt.aggregateValue(empty_array_ty, &.{});
28456 const empty_array_ptr = try sema.uavRef(empty_array_val);28457 const empty_array_ptr = try sema.uavRef(empty_array_val);
28457 return sema.coerceArrayPtrToSlice(block, dest_ty, empty_array_ptr, inst_src);28458 return sema.coerceArrayPtrToSlice(block, dest_ty, empty_array_ptr, inst_src);
test/behavior/cast.zig+20
...@@ -3164,3 +3164,23 @@ test "coercing a coerced function" {...@@ -3164,3 +3164,23 @@ test "coercing a coerced function" {
3164 };3164 };
3165 try S.doTheTest();3165 try S.doTheTest();
3166}3166}
3167
3168test "pointer to empty tuple coerces to any slice" {
3169 const tuple_ptr = &.{};
3170
3171 const const_slice_0: []const u8 = tuple_ptr;
3172 const const_slice_1: []const struct {} = tuple_ptr;
3173 const const_slice_2: []align(64) const struct { x: u8 } = tuple_ptr;
3174
3175 const mut_slice_0: []const u8 = tuple_ptr;
3176 const mut_slice_1: []const struct {} = tuple_ptr;
3177 const mut_slice_2: []align(64) const struct { x: u8 } = tuple_ptr;
3178
3179 comptime assert(const_slice_0.len == 0);
3180 comptime assert(const_slice_1.len == 0);
3181 comptime assert(const_slice_2.len == 0);
3182
3183 comptime assert(mut_slice_0.len == 0);
3184 comptime assert(mut_slice_1.len == 0);
3185 comptime assert(mut_slice_2.len == 0);
3186}