authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-14 00:08:38+01:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-17 18:50:10-04:00
log3fb5cad07dd3b10ad32a116cbd7195218b0a93fe
treefc4ce5844b794bc131a4dde5b4ae2d4885e29ba4
parent50960fac80b1d04f7858215d963fa64a7583210b

Sema: don't delete reified enum type with error in field

An enum type is kind of like a struct or union type, in that field errors are happening during type resolution. The only difference is that type resolution happens at the time the type is created. So, errors in fields should not cause the type to be deleted: we've already added a reference entry, and incremenetal dependencies which must be invalidated if the compile error is fixed. Once we call `WipEnumType.prepare`, we should never call `WipEnumType.cancel`. This is analagous to logic for enum declarations in `Sema.zirEnumDecl`.

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

src/Sema.zig+3-1
......@@ -22062,7 +22062,8 @@ fn reifyEnum(
2206222062 return Air.internedToRef(ty);
2206322063 },
2206422064 };
22065 errdefer wip_ty.cancel(ip, pt.tid);
22065 var done = false;
22066 errdefer if (!done) wip_ty.cancel(ip, pt.tid);
2206622067
2206722068 if (tag_ty.zigTypeTag(mod) != .Int) {
2206822069 return sema.fail(block, src, "Type.Enum.tag_type must be an integer type", .{});
......@@ -22088,6 +22089,7 @@ fn reifyEnum(
2208822089 try sema.addTypeReferenceEntry(src, wip_ty.index);
2208922090 wip_ty.prepare(ip, new_cau_index, new_namespace_index);
2209022091 wip_ty.setTagTy(ip, tag_ty.toIntern());
22092 done = true;
2209122093
2209222094 for (0..fields_len) |field_idx| {
2209322095 const field_info = try fields_val.elemValue(pt, field_idx);