@@ -5653,17 +5653,20 @@ void TypeChecker::checkClosureAttributes(ClosureExpr *closure) {
56535653
56545654void AttributeChecker::visitCompletionHandlerAsyncAttr (
56555655 CompletionHandlerAsyncAttr *attr) {
5656- AbstractFunctionDecl *AFD = dyn_cast<AbstractFunctionDecl>(D);
5657- if (!AFD)
5658- return ;
5659-
5660- evaluateOrDefault (Ctx.evaluator ,
5661- TypeCheckCompletionHandlerAsyncAttrRequest{AFD, attr}, {});
5656+ if (AbstractFunctionDecl *AFD = dyn_cast<AbstractFunctionDecl>(D))
5657+ AFD->getAsyncAlternative ();
56625658}
56635659
5664- bool TypeCheckCompletionHandlerAsyncAttrRequest::evaluate (
5665- Evaluator &evaluator, AbstractFunctionDecl *attachedFunctionDecl,
5666- CompletionHandlerAsyncAttr *attr) const {
5660+ AbstractFunctionDecl *AsyncAlternativeRequest::evaluate (
5661+ Evaluator &evaluator, AbstractFunctionDecl *attachedFunctionDecl) const {
5662+ auto attr = attachedFunctionDecl->getAttrs ()
5663+ .getAttribute <CompletionHandlerAsyncAttr>();
5664+ if (!attr)
5665+ return nullptr ;
5666+
5667+ if (attr->AsyncFunctionDecl )
5668+ return attr->AsyncFunctionDecl ;
5669+
56675670 auto &Diags = attachedFunctionDecl->getASTContext ().Diags ;
56685671 // Check phases:
56695672 // 1. Attached function shouldn't be async and should have enough args
@@ -5681,7 +5684,7 @@ bool TypeCheckCompletionHandlerAsyncAttrRequest::evaluate(
56815684 diag::attr_completion_handler_async_handler_not_func, attr);
56825685 Diags.diagnose (attachedFunctionDecl->getAsyncLoc (),
56835686 diag::note_attr_function_declared_async);
5684- return false ;
5687+ return nullptr ;
56855688 }
56865689
56875690 const ParameterList *attachedFunctionParams =
@@ -5690,15 +5693,15 @@ bool TypeCheckCompletionHandlerAsyncAttrRequest::evaluate(
56905693 if (attachedFunctionParams->size () == 0 ) {
56915694 Diags.diagnose (attr->getLocation (),
56925695 diag::attr_completion_handler_async_handler_not_func, attr);
5693- return false ;
5696+ return nullptr ;
56945697 }
56955698 size_t completionHandlerIndex = attr->CompletionHandlerIndexLoc .isValid ()
56965699 ? attr->CompletionHandlerIndex
56975700 : attachedFunctionParams->size () - 1 ;
56985701 if (attachedFunctionParams->size () < completionHandlerIndex) {
56995702 Diags.diagnose (attr->CompletionHandlerIndexLoc ,
57005703 diag::attr_completion_handler_async_handler_out_of_range);
5701- return false ;
5704+ return nullptr ;
57025705 }
57035706
57045707 // Phase 2: Typecheck the completion handler
@@ -5718,7 +5721,7 @@ bool TypeCheckCompletionHandlerAsyncAttrRequest::evaluate(
57185721 completionHandlerParamDecl->getType ())
57195722 .highlight (
57205723 completionHandlerParamDecl->getTypeRepr ()->getSourceRange ());
5721- return false ;
5724+ return nullptr ;
57225725 }
57235726
57245727 auto handlerTypeRepr =
@@ -5759,7 +5762,7 @@ bool TypeCheckCompletionHandlerAsyncAttrRequest::evaluate(
57595762 handlerTypeAttrs->getLoc (TAK_autoclosure),
57605763 diag::note_attr_completion_handler_async_handler_attr_req, false ,
57615764 " autoclosure" );
5762- return false ;
5765+ return nullptr ;
57635766 }
57645767 }
57655768
@@ -5793,7 +5796,7 @@ bool TypeCheckCompletionHandlerAsyncAttrRequest::evaluate(
57935796 // should return all of those types in a tuple
57945797
57955798 SmallVector<ValueDecl *, 2 > allCandidates;
5796- lookupReplacedDecl (attr->getAsyncFunctionName () , attr, attachedFunctionDecl,
5799+ lookupReplacedDecl (attr->AsyncFunctionName , attr, attachedFunctionDecl,
57975800 allCandidates);
57985801 SmallVector<AbstractFunctionDecl *, 2 > candidates;
57995802 candidates.reserve (allCandidates.size ());
@@ -5810,21 +5813,20 @@ bool TypeCheckCompletionHandlerAsyncAttrRequest::evaluate(
58105813 if (candidates.empty ()) {
58115814 Diags.diagnose (attr->AsyncFunctionNameLoc ,
58125815 diag::attr_completion_handler_async_no_suitable_function,
5813- attr->getAsyncFunctionName () );
5814- return false ;
5816+ attr->AsyncFunctionName );
5817+ return nullptr ;
58155818 } else if (candidates.size () > 1 ) {
58165819 Diags.diagnose (attr->AsyncFunctionNameLoc ,
58175820 diag::attr_completion_handler_async_ambiguous_function,
5818- attr, attr->getAsyncFunctionName () );
5821+ attr, attr->AsyncFunctionName );
58195822
58205823 for (AbstractFunctionDecl *candidate : candidates) {
58215824 Diags.diagnose (candidate->getLoc (), diag::decl_declared_here,
58225825 candidate->getName ());
58235826 }
5824- return false ;
5827+ return nullptr ;
58255828 }
5826- attr->AsyncFunctionDecl = candidates.front ();
5827- }
58285829
5829- return true ;
5830+ return candidates.front ();
5831+ }
58305832}
0 commit comments