@@ -6583,6 +6583,11 @@ bool EnumDecl::hasOnlyCasesWithoutAssociatedValues() const {
6583
6583
return !hasAssociatedValues;
6584
6584
}
6585
6585
6586
+ bool EnumDecl::treatAsExhaustiveForDiags (const DeclContext *useDC) const {
6587
+ return isFormallyExhaustive (useDC) ||
6588
+ (useDC && getModuleContext ()->inSamePackage (useDC->getParentModule ()));
6589
+ }
6590
+
6586
6591
bool EnumDecl::isFormallyExhaustive (const DeclContext *useDC) const {
6587
6592
// Enums explicitly marked frozen are exhaustive.
6588
6593
if (getAttrs ().hasAttribute <FrozenAttr>())
@@ -6600,14 +6605,10 @@ bool EnumDecl::isFormallyExhaustive(const DeclContext *useDC) const {
6600
6605
return true ;
6601
6606
6602
6607
// 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 );
6607
6610
if (!accessScope.isPublicOrPackage ())
6608
6611
return true ;
6609
- if (useDC && bypassResilienceInPackage (useDC->getParentModule ()))
6610
- return true ;
6611
6612
6612
6613
// All other checks are use-site specific; with no further information, the
6613
6614
// enum must be treated non-exhaustively.
@@ -6639,11 +6640,13 @@ bool EnumDecl::isEffectivelyExhaustive(ModuleDecl *M,
6639
6640
if (isObjC ())
6640
6641
return false ;
6641
6642
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" );
6647
6650
return !isResilient (M, expansion);
6648
6651
}
6649
6652
0 commit comments