authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-03-25 13:57:55+00:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-03-31 17:36:44+02:00
log6ac462b08827a70a6bc2c1c695372a2f34075234
tree8b9b7d7d4bab04dd6af097fa4154c39bee64dcac
parent9025f73733211b7748e64ce99368503618fc164c
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Zcu: resolve layout of analyzed declaration type

Resolves: #19888

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

src/Zcu/PerThread.zig+2
...@@ -1444,6 +1444,8 @@ fn analyzeNavType(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileEr...@@ -1444,6 +1444,8 @@ fn analyzeNavType(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileEr
1444 break :ty .fromInterned(type_ref.toInterned().?);1444 break :ty .fromInterned(type_ref.toInterned().?);
1445 };1445 };
14461446
1447 try resolved_ty.resolveLayout(pt);
1448
1447 // In the case where the type is specified, this function is also responsible for resolving1449 // In the case where the type is specified, this function is also responsible for resolving
1448 // the pointer modifiers, i.e. alignment, linksection, addrspace.1450 // the pointer modifiers, i.e. alignment, linksection, addrspace.
1449 const modifiers = try sema.resolveNavPtrModifiers(&block, zir_decl, inst_resolved.inst, resolved_ty);1451 const modifiers = try sema.resolveNavPtrModifiers(&block, zir_decl, inst_resolved.inst, resolved_ty);
test/behavior/generics.zig+15
...@@ -631,3 +631,18 @@ test "instantiate coerced generic function" {...@@ -631,3 +631,18 @@ test "instantiate coerced generic function" {
631 var x: u8 = 20;631 var x: u8 = 20;
632 try coerced(u8, &x);632 try coerced(u8, &x);
633}633}
634
635test "generic struct captures slice of another struct" {
636 const S = struct {
637 const Foo = struct { x: u32 };
638 const foo_array: [2]Foo = undefined;
639
640 fn Bar(foo_slice: []const Foo) type {
641 return struct {
642 const foo_ptr: [*]const Foo = foo_slice.ptr;
643 };
644 }
645 };
646 const T = S.Bar(&S.foo_array);
647 comptime std.debug.assert(T.foo_ptr == &S.foo_array);
648}