@@ -3449,8 +3449,16 @@ static Optional<ActorIsolation> getIsolationFromWrappers(
3449
3449
3450
3450
if (!nominal->getParentSourceFile ())
3451
3451
return None;
3452
-
3453
- Optional<ActorIsolation> foundIsolation;
3452
+
3453
+ ASTContext &ctx = nominal->getASTContext ();
3454
+ if (ctx.isSwiftVersionAtLeast (6 )) {
3455
+ // In Swift 6, we no longer infer isolation of a nominal type based
3456
+ // on property wrappers used in its stored properties
3457
+ return None;
3458
+ }
3459
+
3460
+ Optional<std::pair<ActorIsolation, Type>> foundIsolationAndType;
3461
+
3454
3462
for (auto member : nominal->getMembers ()) {
3455
3463
auto var = dyn_cast<VarDecl>(member);
3456
3464
if (!var || !var->isInstanceMember ())
@@ -3475,19 +3483,36 @@ static Optional<ActorIsolation> getIsolationFromWrappers(
3475
3483
3476
3484
case ActorIsolation::GlobalActor:
3477
3485
case ActorIsolation::GlobalActorUnsafe:
3478
- if (!foundIsolation) {
3479
- foundIsolation = isolation;
3480
- continue ;
3486
+ if (!foundIsolationAndType) {
3487
+ if (auto propertyWrapperType = var->getAttachedPropertyWrapperType (0 )) {
3488
+ foundIsolationAndType = { isolation, propertyWrapperType };
3489
+ continue ;
3490
+ }
3481
3491
}
3482
3492
3483
- if (*foundIsolation != isolation)
3493
+ if (foundIsolationAndType-> first != isolation)
3484
3494
return None;
3485
3495
3486
3496
break ;
3487
3497
}
3488
3498
}
3489
3499
3490
- return foundIsolation;
3500
+ if (foundIsolationAndType) {
3501
+ // We are inferring isolation for the type because
3502
+ // it contains an actor-isolated property wrapper.
3503
+ // Warn that this inferrence will be going away in
3504
+ // Swift 6
3505
+ const ActorIsolation isolation = foundIsolationAndType->first ;
3506
+ const Type type = foundIsolationAndType->second ;
3507
+
3508
+ nominal->diagnose (diag::actor_isolation_inferred_from_property_wrapper,
3509
+ nominal->getName (), isolation, " '@" +type->getString ()+" '" )
3510
+ .fixItInsert (nominal->getAttributeInsertionLoc (false ), " @" + isolation.getGlobalActor ().getString ());
3511
+ return isolation;
3512
+ }
3513
+ else {
3514
+ return None;
3515
+ }
3491
3516
}
3492
3517
3493
3518
namespace {
@@ -4063,8 +4088,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
4063
4088
if (auto inferred = inferredIsolation (*conformanceIsolation))
4064
4089
return inferred;
4065
4090
4066
- // If the declaration is a nominal type and any property wrappers on
4067
- // its stored properties require isolation, use that.
4091
+ // Before Swift 6: If the declaration is a nominal type and any property
4092
+ // wrappers on its stored properties require isolation, use that.
4068
4093
if (auto wrapperIsolation = getIsolationFromWrappers (nominal)) {
4069
4094
if (auto inferred = inferredIsolation (*wrapperIsolation))
4070
4095
return inferred;
0 commit comments