From 3fb5cad07dd3b10ad32a116cbd7195218b0a93fe Mon Sep 17 00:00:00 2001 From: mlugg Date: Wed, 14 Aug 2024 00:08:38 +0100 Subject: [PATCH] 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`. --- src/Sema.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Sema.zig b/src/Sema.zig index a679f69a9c..1aedd745ea 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -22062,7 +22062,8 @@ fn reifyEnum( return Air.internedToRef(ty); }, }; - errdefer wip_ty.cancel(ip, pt.tid); + var done = false; + errdefer if (!done) wip_ty.cancel(ip, pt.tid); if (tag_ty.zigTypeTag(mod) != .Int) { return sema.fail(block, src, "Type.Enum.tag_type must be an integer type", .{}); @@ -22088,6 +22089,7 @@ fn reifyEnum( try sema.addTypeReferenceEntry(src, wip_ty.index); wip_ty.prepare(ip, new_cau_index, new_namespace_index); wip_ty.setTagTy(ip, tag_ty.toIntern()); + done = true; for (0..fields_len) |field_idx| { const field_info = try fields_val.elemValue(pt, field_idx);