@@ -44,6 +44,32 @@ void PostfixCompletionCallback::fallbackTypeCheck(DeclContext *DC) {
4444 [&](const Solution &S) { sawSolution (S); });
4545}
4646
47+ static ClosureActorIsolation
48+ getClosureActorIsolation (const Solution &S, AbstractClosureExpr *ACE) {
49+ auto getType = [&S](Expr *E) -> Type {
50+ // Prefer the contextual type of the closure because it might be 'weaker'
51+ // than the type determined for the closure by the constraints system. E.g.
52+ // the contextual type might have a global actor attribute but because no
53+ // methods from that global actor are called in the closure, the closure has
54+ // a non-actor type.
55+ auto target = S.solutionApplicationTargets .find (dyn_cast<ClosureExpr>(E));
56+ if (target != S.solutionApplicationTargets .end ()) {
57+ if (auto Ty = target->second .getClosureContextualType ()) {
58+ return Ty;
59+ }
60+ }
61+ if (!S.hasType (E)) {
62+ return Type ();
63+ }
64+ return getTypeForCompletion (S, E);
65+ };
66+ auto getClosureActorIsolationThunk = [&S](AbstractClosureExpr *ACE) {
67+ return getClosureActorIsolation (S, ACE);
68+ };
69+ return determineClosureActorIsolation (ACE, getType,
70+ getClosureActorIsolationThunk);
71+ }
72+
4773void PostfixCompletionCallback::sawSolutionImpl (
4874 const constraints::Solution &S) {
4975 auto &CS = S.getConstraintSystem ();
@@ -60,29 +86,45 @@ void PostfixCompletionCallback::sawSolutionImpl(
6086 auto *Locator = CS.getConstraintLocator (SemanticExpr);
6187 Type ExpectedTy = getTypeForCompletion (S, CompletionExpr);
6288 Expr *ParentExpr = CS.getParentExpr (CompletionExpr);
63- if (!ParentExpr)
89+ if (!ParentExpr && !ExpectedTy )
6490 ExpectedTy = CS.getContextualType (CompletionExpr, /* forConstraint=*/ false );
6591
6692 auto *CalleeLocator = S.getCalleeLocator (Locator);
6793 ValueDecl *ReferencedDecl = nullptr ;
6894 if (auto SelectedOverload = S.getOverloadChoiceIfAvailable (CalleeLocator))
6995 ReferencedDecl = SelectedOverload->choice .getDeclOrNull ();
7096
97+ llvm::DenseMap<AbstractClosureExpr *, ClosureActorIsolation>
98+ ClosureActorIsolations;
7199 bool IsAsync = isContextAsync (S, DC);
100+ for (auto SAT : S.solutionApplicationTargets ) {
101+ if (auto ACE = getAsExpr<AbstractClosureExpr>(SAT.second .getAsASTNode ())) {
102+ ClosureActorIsolations[ACE] = getClosureActorIsolation (S, ACE);
103+ }
104+ }
72105
73106 auto Key = std::make_pair (BaseTy, ReferencedDecl);
74107 auto Ret = BaseToSolutionIdx.insert ({Key, Results.size ()});
75108 if (Ret.second ) {
76109 bool ISDMT = S.isStaticallyDerivedMetatype (ParsedExpr);
77110 bool ImplicitReturn = isImplicitSingleExpressionReturn (CS, CompletionExpr);
78- bool DisallowVoid = ExpectedTy
79- ? !ExpectedTy->isVoid ()
80- : !ParentExpr && CS.getContextualTypePurpose (
81- CompletionExpr) != CTP_Unused;
111+ bool DisallowVoid = false ;
112+ DisallowVoid |= ExpectedTy && !ExpectedTy->isVoid ();
113+ DisallowVoid |= !ParentExpr &&
114+ CS.getContextualTypePurpose (CompletionExpr) != CTP_Unused;
115+ for (auto SAT : S.solutionApplicationTargets ) {
116+ if (DisallowVoid) {
117+ // DisallowVoid is already set. No need to iterate further.
118+ break ;
119+ }
120+ if (SAT.second .getAsExpr () == CompletionExpr) {
121+ DisallowVoid |= SAT.second .getExprContextualTypePurpose () != CTP_Unused;
122+ }
123+ }
82124
83125 Results.push_back ({BaseTy, ReferencedDecl,
84126 /* ExpectedTypes=*/ {}, DisallowVoid, ISDMT,
85- ImplicitReturn, IsAsync});
127+ ImplicitReturn, IsAsync, ClosureActorIsolations });
86128 if (ExpectedTy) {
87129 Results.back ().ExpectedTypes .push_back (ExpectedTy);
88130 }
@@ -122,6 +164,7 @@ void PostfixCompletionCallback::deliverResults(
122164 Lookup.shouldCheckForDuplicates (Results.size () > 1 );
123165 for (auto &Result : Results) {
124166 Lookup.setCanCurrDeclContextHandleAsync (Result.IsInAsyncContext );
167+ Lookup.setClosureActorIsolations (Result.ClosureActorIsolations );
125168 Lookup.setIsStaticMetatype (Result.BaseIsStaticMetaType );
126169 Lookup.getPostfixKeywordCompletions (Result.BaseTy , BaseExpr);
127170 Lookup.setExpectedTypes (Result.ExpectedTypes ,
0 commit comments