@@ -2065,6 +2065,14 @@ bool PatternBindingDecl::isAsyncLet() const {
20652065 return false ;
20662066}
20672067
2068+ ActorIsolation
2069+ PatternBindingDecl::getInitializerIsolation (unsigned i) const {
2070+ auto *var = getPatternList ()[i].getAnchoringVarDecl ();
2071+ if (!var)
2072+ return ActorIsolation::forUnspecified ();
2073+
2074+ return var->getInitializerIsolation ();
2075+ }
20682076
20692077bool PatternBindingDecl::hasStorage () const {
20702078 // Walk the pattern, to check to see if any of the VarDecls included in it
@@ -7046,6 +7054,14 @@ Expr *VarDecl::getParentExecutableInitializer() const {
70467054 return nullptr ;
70477055}
70487056
7057+ ActorIsolation VarDecl::getInitializerIsolation () const {
7058+ auto *mutableThis = const_cast <VarDecl *>(this );
7059+ return evaluateOrDefault (
7060+ getASTContext ().evaluator ,
7061+ DefaultInitializerIsolation{mutableThis},
7062+ ActorIsolation::forUnspecified ());
7063+ }
7064+
70497065SourceRange VarDecl::getSourceRange () const {
70507066 if (auto Param = dyn_cast<ParamDecl>(this ))
70517067 return Param->getSourceRange ();
@@ -10266,8 +10282,25 @@ ActorIsolation swift::getActorIsolationOfContext(
1026610282 if (auto *vd = dyn_cast_or_null<ValueDecl>(dcToUse->getAsDecl ()))
1026710283 return getActorIsolation (vd);
1026810284
10269- if (auto *var = dcToUse->getNonLocalVarDecl ())
10285+ // In the context of the initializing or default-value expression of a
10286+ // stored property, the isolation varies between instance and type members:
10287+ // - For a static stored property, the isolation matches the VarDecl.
10288+ // Static properties are initialized upon first use, so the isolation
10289+ // of the initializer must match the isolation required to access the
10290+ // property.
10291+ // - For a field of a nominal type, the expression can require a specific
10292+ // actor isolation. That default expression may only be used from inits
10293+ // that meet the required isolation.
10294+ if (auto *var = dcToUse->getNonLocalVarDecl ()) {
10295+ auto &ctx = dc->getASTContext ();
10296+ if (ctx.LangOpts .hasFeature (Feature::IsolatedDefaultValues) &&
10297+ var->isInstanceMember () &&
10298+ !var->getAttrs ().hasAttribute <LazyAttr>()) {
10299+ return ActorIsolation::forNonisolated ();
10300+ }
10301+
1027010302 return getActorIsolation (var);
10303+ }
1027110304
1027210305 if (auto *closure = dyn_cast<AbstractClosureExpr>(dcToUse)) {
1027310306 return getClosureActorIsolation (closure);
0 commit comments