From f296eec294f7263c9e809c1d825a13a395e5234b Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 25 Mar 2025 13:57:55 +0000 Subject: [PATCH] Zcu: resolve layout of analyzed declaration type Resolves: #19888 --- src/Zcu/PerThread.zig | 2 ++ test/behavior/generics.zig | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index c537a6c921..1031ee6c54 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -1444,6 +1444,8 @@ fn analyzeNavType(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileEr break :ty .fromInterned(type_ref.toInterned().?); }; + try resolved_ty.resolveLayout(pt); + // In the case where the type is specified, this function is also responsible for resolving // the pointer modifiers, i.e. alignment, linksection, addrspace. const modifiers = try sema.resolveNavPtrModifiers(&block, zir_decl, inst_resolved.inst, resolved_ty); diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig index 89087e6214..50c329d721 100644 --- a/test/behavior/generics.zig +++ b/test/behavior/generics.zig @@ -631,3 +631,18 @@ test "instantiate coerced generic function" { var x: u8 = 20; try coerced(u8, &x); } + +test "generic struct captures slice of another struct" { + const S = struct { + const Foo = struct { x: u32 }; + const foo_array: [2]Foo = undefined; + + fn Bar(foo_slice: []const Foo) type { + return struct { + const foo_ptr: [*]const Foo = foo_slice.ptr; + }; + } + }; + const T = S.Bar(&S.foo_array); + comptime std.debug.assert(T.foo_ptr == &S.foo_array); +}