Skip to content

Zcu: resolve layout of analyzed declaration type #23354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Zcu/PerThread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions test/behavior/generics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading