@@ -2082,6 +2082,10 @@ namespace {
20822082 llvm::function_ref<Type(Expr *)> getType;
20832083 llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
20842084 getClosureActorIsolation;
2085+ // / Whether to check if the closure captures an `isolated` parameter.
2086+ // / This is needed as a workaround during code completion, which doesn't
2087+ // / have types applied to the AST and thus doesn't have captures computed.
2088+ bool checkIsolatedCapture;
20852089
20862090 SourceLoc requiredIsolationLoc;
20872091
@@ -2578,9 +2582,11 @@ namespace {
25782582 const DeclContext *dc,
25792583 llvm::function_ref<Type(Expr *)> getType = __Expr_getType,
25802584 llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
2581- getClosureActorIsolation = __AbstractClosureExpr_getActorIsolation)
2585+ getClosureActorIsolation = __AbstractClosureExpr_getActorIsolation,
2586+ bool checkIsolatedCapture = true )
25822587 : ctx(dc->getASTContext ()), getType(getType),
2583- getClosureActorIsolation(getClosureActorIsolation) {
2588+ getClosureActorIsolation(getClosureActorIsolation),
2589+ checkIsolatedCapture(checkIsolatedCapture) {
25842590 contextStack.push_back (dc);
25852591 }
25862592
@@ -4193,9 +4199,16 @@ namespace {
41934199 }
41944200
41954201 case ActorIsolation::ActorInstance: {
4196- if (auto param = closure->getCaptureInfo ().getIsolatedParamCapture ())
4197- return ActorIsolation::forActorInstanceCapture (param)
4198- .withPreconcurrency (preconcurrency);
4202+ if (checkIsolatedCapture) {
4203+ if (auto param = closure->getCaptureInfo ().getIsolatedParamCapture ())
4204+ return ActorIsolation::forActorInstanceCapture (param)
4205+ .withPreconcurrency (preconcurrency);
4206+ } else {
4207+ // If we don't have capture information during code completion, assume
4208+ // that the closure captures the `isolated` parameter from the parent
4209+ // context.
4210+ return parentIsolation;
4211+ }
41994212
42004213 return ActorIsolation::forNonisolated (/* unsafe=*/ false )
42014214 .withPreconcurrency (preconcurrency);
@@ -4325,7 +4338,8 @@ ActorIsolation swift::determineClosureActorIsolation(
43254338 llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
43264339 getClosureActorIsolation) {
43274340 ActorIsolationChecker checker (closure->getParent (), getType,
4328- getClosureActorIsolation);
4341+ getClosureActorIsolation,
4342+ /* checkIsolatedCapture=*/ false );
43294343 return checker.determineClosureIsolation (closure);
43304344}
43314345
0 commit comments