@@ -852,8 +852,9 @@ namespace {
852852 }
853853
854854 private:
855- // / If the expression is a reference to `self`, return the 'self' parameter.
856- static VarDecl *getSelfReference (Expr *expr) {
855+ // / If the expression is a reference to `self`, return the context of
856+ // / the 'self' parameter.
857+ static DeclContext *getSelfReferenceContext (Expr *expr) {
857858 // Look through identity expressions and implicit conversions.
858859 Expr *prior;
859860 do {
@@ -867,13 +868,25 @@ namespace {
867868
868869 // 'super' references always act on self.
869870 if (auto super = dyn_cast<SuperRefExpr>(expr))
870- return super->getSelf ();
871+ return super->getSelf ()-> getDeclContext () ;
871872
872873 // Declaration references to 'self'.
873874 if (auto declRef = dyn_cast<DeclRefExpr>(expr)) {
874- if (auto var = dyn_cast<VarDecl>(declRef->getDecl ()))
875+ if (auto var = dyn_cast<VarDecl>(declRef->getDecl ())) {
875876 if (var->isSelfParameter ())
876- return var;
877+ return var->getDeclContext ();
878+
879+ // If this is a 'self' capture in a capture list, recurse through
880+ // the capture list entry's initializer to find the original 'self'.
881+ if (var->isSelfParamCapture ()) {
882+ for (auto capture : var->getParentCaptureList ()->getCaptureList ()) {
883+ if (capture.Var == var) {
884+ expr = capture.Init ->getInit (0 );
885+ return getSelfReferenceContext (expr);
886+ }
887+ }
888+ }
889+ }
877890 }
878891
879892 // Not a self reference.
@@ -1250,8 +1263,8 @@ namespace {
12501263
12511264 case ActorIsolationRestriction::ActorSelf: {
12521265 // Must reference actor-isolated state on 'self'.
1253- auto selfVar = getSelfReference (base);
1254- if (!selfVar ) {
1266+ auto *selfDC = getSelfReferenceContext (base);
1267+ if (!selfDC ) {
12551268 // actor-isolated non-self calls are implicitly async and thus OK.
12561269 if (maybeImplicitAsync && isa<AbstractFunctionDecl>(member)) {
12571270 markNearestCallAsImplicitlyAsync ();
@@ -1268,8 +1281,7 @@ namespace {
12681281 }
12691282
12701283 // Check whether the context of 'self' is actor-isolated.
1271- switch (auto contextIsolation = getActorIsolation (
1272- cast<ValueDecl>(selfVar->getDeclContext ()->getAsDecl ()))) {
1284+ switch (auto contextIsolation = getActorIsolationOfContext (selfDC)) {
12731285 case ActorIsolation::ActorInstance:
12741286 // An escaping partial application of something that is part of
12751287 // the actor's isolated state is never permitted.
@@ -1312,8 +1324,7 @@ namespace {
13121324
13131325 // Check whether we are in a context that will not execute concurrently
13141326 // with the context of 'self'.
1315- if (mayExecuteConcurrentlyWith (
1316- getDeclContext (), selfVar->getDeclContext ())) {
1327+ if (mayExecuteConcurrentlyWith (getDeclContext (), selfDC)) {
13171328 ctx.Diags .diagnose (
13181329 memberLoc, diag::actor_isolated_concurrent_access,
13191330 member->getDescriptiveKind (), member->getName ());
@@ -1886,13 +1897,6 @@ ActorIsolation ActorIsolationRequest::evaluate(
18861897 return defaultIsolation;
18871898}
18881899
1889- ActorIsolation swift::getActorIsolation (ValueDecl *value) {
1890- auto &ctx = value->getASTContext ();
1891- return evaluateOrDefault (
1892- ctx.evaluator , ActorIsolationRequest{value},
1893- ActorIsolation::forUnspecified ());
1894- }
1895-
18961900void swift::checkOverrideActorIsolation (ValueDecl *value) {
18971901 if (isa<TypeDecl>(value))
18981902 return ;
0 commit comments