@@ -2088,6 +2088,14 @@ bool PatternBindingDecl::isAsyncLet() const {
20882088 return false ;
20892089}
20902090
2091+ ActorIsolation
2092+ PatternBindingDecl::getInitializerIsolation (unsigned i) const {
2093+ auto *var = getPatternList ()[i].getAnchoringVarDecl ();
2094+ if (!var)
2095+ return ActorIsolation::forUnspecified ();
2096+
2097+ return var->getInitializerIsolation ();
2098+ }
20912099
20922100bool PatternBindingDecl::hasStorage () const {
20932101 // Walk the pattern, to check to see if any of the VarDecls included in it
@@ -7127,6 +7135,14 @@ Expr *VarDecl::getParentExecutableInitializer() const {
71277135 return nullptr ;
71287136}
71297137
7138+ ActorIsolation VarDecl::getInitializerIsolation () const {
7139+ auto *mutableThis = const_cast <VarDecl *>(this );
7140+ return evaluateOrDefault (
7141+ getASTContext ().evaluator ,
7142+ DefaultInitializerIsolation{mutableThis},
7143+ ActorIsolation::forUnspecified ());
7144+ }
7145+
71307146SourceRange VarDecl::getSourceRange () const {
71317147 if (auto Param = dyn_cast<ParamDecl>(this ))
71327148 return Param->getSourceRange ();
@@ -10445,8 +10461,25 @@ ActorIsolation swift::getActorIsolationOfContext(
1044510461 if (auto *vd = dyn_cast_or_null<ValueDecl>(dcToUse->getAsDecl ()))
1044610462 return getActorIsolation (vd);
1044710463
10448- if (auto *var = dcToUse->getNonLocalVarDecl ())
10464+ // In the context of the initializing or default-value expression of a
10465+ // stored property, the isolation varies between instance and type members:
10466+ // - For a static stored property, the isolation matches the VarDecl.
10467+ // Static properties are initialized upon first use, so the isolation
10468+ // of the initializer must match the isolation required to access the
10469+ // property.
10470+ // - For a field of a nominal type, the expression can require a specific
10471+ // actor isolation. That default expression may only be used from inits
10472+ // that meet the required isolation.
10473+ if (auto *var = dcToUse->getNonLocalVarDecl ()) {
10474+ auto &ctx = dc->getASTContext ();
10475+ if (ctx.LangOpts .hasFeature (Feature::IsolatedDefaultArguments) &&
10476+ var->isInstanceMember () &&
10477+ !var->getAttrs ().hasAttribute <LazyAttr>()) {
10478+ return ActorIsolation::forNonisolated ();
10479+ }
10480+
1044910481 return getActorIsolation (var);
10482+ }
1045010483
1045110484 if (auto *closure = dyn_cast<AbstractClosureExpr>(dcToUse)) {
1045210485 return getClosureActorIsolation (closure);
0 commit comments