@@ -2082,6 +2082,10 @@ namespace {
2082
2082
llvm::function_ref<Type(Expr *)> getType;
2083
2083
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
2084
2084
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;
2085
2089
2086
2090
SourceLoc requiredIsolationLoc;
2087
2091
@@ -2578,9 +2582,11 @@ namespace {
2578
2582
const DeclContext *dc,
2579
2583
llvm::function_ref<Type(Expr *)> getType = __Expr_getType,
2580
2584
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
2581
- getClosureActorIsolation = __AbstractClosureExpr_getActorIsolation)
2585
+ getClosureActorIsolation = __AbstractClosureExpr_getActorIsolation,
2586
+ bool checkIsolatedCapture = true )
2582
2587
: ctx(dc->getASTContext ()), getType(getType),
2583
- getClosureActorIsolation(getClosureActorIsolation) {
2588
+ getClosureActorIsolation(getClosureActorIsolation),
2589
+ checkIsolatedCapture(checkIsolatedCapture) {
2584
2590
contextStack.push_back (dc);
2585
2591
}
2586
2592
@@ -4193,9 +4199,16 @@ namespace {
4193
4199
}
4194
4200
4195
4201
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
+ }
4199
4212
4200
4213
return ActorIsolation::forNonisolated (/* unsafe=*/ false )
4201
4214
.withPreconcurrency (preconcurrency);
@@ -4325,7 +4338,8 @@ ActorIsolation swift::determineClosureActorIsolation(
4325
4338
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
4326
4339
getClosureActorIsolation) {
4327
4340
ActorIsolationChecker checker (closure->getParent (), getType,
4328
- getClosureActorIsolation);
4341
+ getClosureActorIsolation,
4342
+ /* checkIsolatedCapture=*/ false );
4329
4343
return checker.determineClosureIsolation (closure);
4330
4344
}
4331
4345
0 commit comments