@@ -2088,6 +2088,14 @@ bool PatternBindingDecl::isAsyncLet() const {
2088
2088
return false ;
2089
2089
}
2090
2090
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
+ }
2091
2099
2092
2100
bool PatternBindingDecl::hasStorage () const {
2093
2101
// Walk the pattern, to check to see if any of the VarDecls included in it
@@ -7127,6 +7135,14 @@ Expr *VarDecl::getParentExecutableInitializer() const {
7127
7135
return nullptr ;
7128
7136
}
7129
7137
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
+
7130
7146
SourceRange VarDecl::getSourceRange () const {
7131
7147
if (auto Param = dyn_cast<ParamDecl>(this ))
7132
7148
return Param->getSourceRange ();
@@ -10445,8 +10461,25 @@ ActorIsolation swift::getActorIsolationOfContext(
10445
10461
if (auto *vd = dyn_cast_or_null<ValueDecl>(dcToUse->getAsDecl ()))
10446
10462
return getActorIsolation (vd);
10447
10463
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
+
10449
10481
return getActorIsolation (var);
10482
+ }
10450
10483
10451
10484
if (auto *closure = dyn_cast<AbstractClosureExpr>(dcToUse)) {
10452
10485
return getClosureActorIsolation (closure);
0 commit comments