@@ -3622,8 +3622,16 @@ static Optional<ActorIsolation> getIsolationFromWrappers(
3622
3622
3623
3623
if (!nominal->getParentSourceFile ())
3624
3624
return None;
3625
-
3626
- Optional<ActorIsolation> foundIsolation;
3625
+
3626
+ ASTContext &ctx = nominal->getASTContext ();
3627
+ if (ctx.isSwiftVersionAtLeast (6 )) {
3628
+ // In Swift 6, we no longer infer isolation of a nominal type based
3629
+ // on property wrappers used in its stored properties
3630
+ return None;
3631
+ }
3632
+
3633
+ Optional<std::pair<ActorIsolation, Type>> foundIsolationAndType;
3634
+
3627
3635
for (auto member : nominal->getMembers ()) {
3628
3636
auto var = dyn_cast<VarDecl>(member);
3629
3637
if (!var || !var->isInstanceMember ())
@@ -3648,19 +3656,36 @@ static Optional<ActorIsolation> getIsolationFromWrappers(
3648
3656
3649
3657
case ActorIsolation::GlobalActor:
3650
3658
case ActorIsolation::GlobalActorUnsafe:
3651
- if (!foundIsolation) {
3652
- foundIsolation = isolation;
3653
- continue ;
3659
+ if (!foundIsolationAndType) {
3660
+ if (auto propertyWrapperType = var->getAttachedPropertyWrapperType (0 )) {
3661
+ foundIsolationAndType = { isolation, propertyWrapperType };
3662
+ continue ;
3663
+ }
3654
3664
}
3655
3665
3656
- if (*foundIsolation != isolation)
3666
+ if (foundIsolationAndType-> first != isolation)
3657
3667
return None;
3658
3668
3659
3669
break ;
3660
3670
}
3661
3671
}
3662
3672
3663
- return foundIsolation;
3673
+ if (foundIsolationAndType) {
3674
+ // We are inferring isolation for the type because
3675
+ // it contains an actor-isolated property wrapper.
3676
+ // Warn that this inferrence will be going away in
3677
+ // Swift 6
3678
+ const ActorIsolation isolation = foundIsolationAndType->first ;
3679
+ const Type type = foundIsolationAndType->second ;
3680
+
3681
+ nominal->diagnose (diag::actor_isolation_inferred_from_property_wrapper,
3682
+ nominal->getName (), isolation, " '@" +type->getString ()+" '" )
3683
+ .fixItInsert (nominal->getAttributeInsertionLoc (false ), " @" + isolation.getGlobalActor ().getString ());
3684
+ return isolation;
3685
+ }
3686
+ else {
3687
+ return None;
3688
+ }
3664
3689
}
3665
3690
3666
3691
namespace {
@@ -4236,8 +4261,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
4236
4261
if (auto inferred = inferredIsolation (*conformanceIsolation))
4237
4262
return inferred;
4238
4263
4239
- // If the declaration is a nominal type and any property wrappers on
4240
- // its stored properties require isolation, use that.
4264
+ // Before Swift 6: If the declaration is a nominal type and any property
4265
+ // wrappers on its stored properties require isolation, use that.
4241
4266
if (auto wrapperIsolation = getIsolationFromWrappers (nominal)) {
4242
4267
if (auto inferred = inferredIsolation (*wrapperIsolation))
4243
4268
return inferred;
0 commit comments