Skip to content

Commit 6ac462b

Browse files
mluggalexrp
authored andcommitted
Zcu: resolve layout of analyzed declaration type
Resolves: #19888
1 parent 9025f73 commit 6ac462b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Zcu/PerThread.zig

+2
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,18 @@ test "instantiate coerced generic function" {
631631
var x: u8 = 20;
632632
try coerced(u8, &x);
633633
}
634+
635+
test "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+
}

0 commit comments

Comments
 (0)