authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-03-25 13:57:55+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-03-29 22:46:31+00:00
logf296eec294f7263c9e809c1d825a13a395e5234b
tree4792ef88c11da542cfa06163ae62bcbcf25623bc
parenteee752ea5a966aafa2c22c4c4ae2ed2c741b1bab

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
14441444 break :ty .fromInterned(type_ref.toInterned().?);
14451445 };
14461446
1447 try resolved_ty.resolveLayout(pt);
1448
14471449 // In the case where the type is specified, this function is also responsible for resolving
14481450 // the pointer modifiers, i.e. alignment, linksection, addrspace.
14491451 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" {
631631 var x: u8 = 20;
632632 try coerced(u8, &x);
633633}
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}