@@ -6583,6 +6583,11 @@ bool EnumDecl::hasOnlyCasesWithoutAssociatedValues() const {
65836583 return !hasAssociatedValues;
65846584}
65856585
6586+ bool EnumDecl::treatAsExhaustiveForDiags (const DeclContext *useDC) const {
6587+ return isFormallyExhaustive (useDC) ||
6588+ (useDC && getModuleContext ()->inSamePackage (useDC->getParentModule ()));
6589+ }
6590+
65866591bool EnumDecl::isFormallyExhaustive (const DeclContext *useDC) const {
65876592 // Enums explicitly marked frozen are exhaustive.
65886593 if (getAttrs ().hasAttribute <FrozenAttr>())
@@ -6600,14 +6605,10 @@ bool EnumDecl::isFormallyExhaustive(const DeclContext *useDC) const {
66006605 return true ;
66016606
66026607 // Non-public, non-versioned enums are always exhaustive.
6603- AccessScope accessScope = getFormalAccessScope (/* useDC*/ nullptr ,
6604- /* respectVersioned*/ true );
6605- // Both public and package enums should behave the same unless
6606- // package enum is optimized with bypassing resilience checks.
6608+ AccessScope accessScope = getFormalAccessScope (/* useDC*/ nullptr ,
6609+ /* respectVersioned*/ true );
66076610 if (!accessScope.isPublicOrPackage ())
66086611 return true ;
6609- if (useDC && bypassResilienceInPackage (useDC->getParentModule ()))
6610- return true ;
66116612
66126613 // All other checks are use-site specific; with no further information, the
66136614 // enum must be treated non-exhaustively.
@@ -6639,11 +6640,13 @@ bool EnumDecl::isEffectivelyExhaustive(ModuleDecl *M,
66396640 if (isObjC ())
66406641 return false ;
66416642
6642- // Otherwise, the only non-exhaustive cases are those that don't have a fixed
6643- // layout.
6644- assert (isFormallyExhaustive (M) == !isResilient (M,ResilienceExpansion::Maximal)
6645- && " ignoring the effects of @inlinable, @testable, and @objc, "
6646- " these should match up" );
6643+ // Otherwise, the only non-exhaustive enums are those that don't have
6644+ // a fixed layout; however, they are treated as exhaustive if package
6645+ // optimization is enabled.
6646+ assert ((isFormallyExhaustive (M) || bypassResilienceInPackage (M)) ==
6647+ !isResilient (M, ResilienceExpansion::Maximal) &&
6648+ " ignoring the effects of @inlinable, @testable, and @objc, "
6649+ " these should match up" );
66476650 return !isResilient (M, expansion);
66486651}
66496652
0 commit comments