authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-31 10:40:27+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-09-01 21:17:00+02:00
logc961124d93a47e9ae317b2e057cf0fe5118303e3
treef4968396923b9f78d7b088436841039241c755a7
parent0a2af0b09a435e95f07fb4624ed1ee1025761a4e

Type: fix layout resolution assertion in `classify`

First spotted in https://codeberg.org/ziglang/zig/pulls/36643, where the author noticed that the assertion in `classify` wasn't tripping when it should have been (which would have made the bug more obvious!). I think that back when I was reworking type resolution, I changed how these assertions worked at some point, and updated `assertHasLayout`, but failed to update the similar logic in `classify`.

1 files changed, 5 insertions(+), 1 deletions(-)

src/Type.zig+5-1
...@@ -209,6 +209,7 @@ pub fn classify(start_ty: Type, zcu: *const Zcu) Class {...@@ -209,6 +209,7 @@ pub fn classify(start_ty: Type, zcu: *const Zcu) Class {
209 const struct_obj = ip.loadStructType(cur_ty.toIntern());209 const struct_obj = ip.loadStructType(cur_ty.toIntern());
210 switch (struct_obj.layout) {210 switch (struct_obj.layout) {
211 .auto, .@"extern" => {211 .auto, .@"extern" => {
212 assert(struct_obj.want_layout);
212 zcu.assertUpToDate(.wrap(.{ .type_layout = cur_ty.toIntern() }));213 zcu.assertUpToDate(.wrap(.{ .type_layout = cur_ty.toIntern() }));
213 break struct_obj.class;214 break struct_obj.class;
214 },215 },
...@@ -222,6 +223,7 @@ pub fn classify(start_ty: Type, zcu: *const Zcu) Class {...@@ -222,6 +223,7 @@ pub fn classify(start_ty: Type, zcu: *const Zcu) Class {
222 const union_obj = ip.loadUnionType(cur_ty.toIntern());223 const union_obj = ip.loadUnionType(cur_ty.toIntern());
223 switch (union_obj.layout) {224 switch (union_obj.layout) {
224 .auto, .@"extern" => {225 .auto, .@"extern" => {
226 assert(union_obj.want_layout);
225 zcu.assertUpToDate(.wrap(.{ .type_layout = cur_ty.toIntern() }));227 zcu.assertUpToDate(.wrap(.{ .type_layout = cur_ty.toIntern() }));
226 break union_obj.class;228 break union_obj.class;
227 },229 },
...@@ -232,8 +234,10 @@ pub fn classify(start_ty: Type, zcu: *const Zcu) Class {...@@ -232,8 +234,10 @@ pub fn classify(start_ty: Type, zcu: *const Zcu) Class {
232 }234 }
233 },235 },
234 .enum_type => {236 .enum_type => {
237 const enum_obj = ip.loadEnumType(cur_ty.toIntern());
238 assert(enum_obj.want_layout);
235 zcu.assertUpToDate(.wrap(.{ .type_layout = cur_ty.toIntern() }));239 zcu.assertUpToDate(.wrap(.{ .type_layout = cur_ty.toIntern() }));
236 cur_ty = .fromInterned(ip.loadEnumType(cur_ty.toIntern()).int_tag_type);240 cur_ty = .fromInterned(enum_obj.int_tag_type);
237 continue;241 continue;
238 },242 },
239243