@@ -1858,35 +1858,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
18581858 Builder.addDeclDocCommentWords (llvm::makeArrayRef (Pairs));
18591859 }
18601860
1861- bool shouldUseFunctionReference (AbstractFunctionDecl *D,
1862- const DynamicLookupInfo &dynamicLookupInfo) {
1863- if (PreferFunctionReferencesToCalls)
1864- return true ;
1865- bool isImplicitlyCurriedIM = isImplicitlyCurriedInstanceMethod (D);
1866-
1867- auto funcTy =
1868- getTypeOfMember (D, dynamicLookupInfo)->getAs <AnyFunctionType>();
1869- if (funcTy && D->getDeclContext ()->isTypeContext () &&
1870- !isImplicitlyCurriedIM) {
1871- funcTy = funcTy->getResult ()->getAs <AnyFunctionType>();
1872- }
1873- if (!funcTy)
1874- return false ;
1875- funcTy = funcTy->removeArgumentLabels (1 )->castTo <AnyFunctionType>();
1876-
1877- for (auto expectedType : expectedTypeContext.possibleTypes ) {
1878- if (!expectedType ||
1879- !expectedType->lookThroughAllOptionalTypes ()->is <AnyFunctionType>())
1880- continue ;
1881-
1882- auto relation =
1883- calculateTypeRelation (funcTy, expectedType, CurrDeclContext);
1884- if (relation >= CodeCompletionResult::ExpectedTypeRelation::Convertible)
1885- return true ;
1886- }
1887- return false ;
1888- }
1889-
18901861 // / Returns \c true if \p TAD is usable as a first type of a requirement in
18911862 // / \c where clause for a context.
18921863 // / \p selfTy must be a \c Self type of the context.
@@ -3388,9 +3359,27 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
33883359 }
33893360
33903361 // / Add the compound function name for the given function.
3391- void addCompoundFunctionName (AbstractFunctionDecl *AFD,
3392- DeclVisibilityKind Reason,
3393- DynamicLookupInfo dynamicLookupInfo) {
3362+ // / Returns \c true if the compound function name is actually used.
3363+ bool addCompoundFunctionNameIfDesiable (AbstractFunctionDecl *AFD,
3364+ DeclVisibilityKind Reason,
3365+ DynamicLookupInfo dynamicLookupInfo) {
3366+ auto funcTy =
3367+ getTypeOfMember (AFD, dynamicLookupInfo)->getAs <AnyFunctionType>();
3368+ if (funcTy && AFD->getDeclContext ()->isTypeContext () &&
3369+ !isImplicitlyCurriedInstanceMethod (AFD)) {
3370+ funcTy = funcTy->getResult ()->getAs <AnyFunctionType>();
3371+ }
3372+
3373+ bool useFunctionReference = PreferFunctionReferencesToCalls;
3374+ if (!useFunctionReference && funcTy) {
3375+ auto maxRel = calculateMaxTypeRelation (funcTy, expectedTypeContext,
3376+ CurrDeclContext);
3377+ useFunctionReference =
3378+ maxRel >= CodeCompletionResult::ExpectedTypeRelation::Convertible;
3379+ }
3380+ if (!useFunctionReference)
3381+ return false ;
3382+
33943383 CommandWordsPairs Pairs;
33953384 CodeCompletionResultBuilder Builder (
33963385 Sink, CodeCompletionResult::ResultKind::Declaration,
@@ -3422,15 +3411,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
34223411 Builder.addRightParen ();
34233412 }
34243413
3425- auto funcTy = getTypeOfMember (AFD, dynamicLookupInfo)->getAs <AnyFunctionType>();
3426- if (funcTy && AFD->getDeclContext ()->isTypeContext () &&
3427- !isImplicitlyCurriedInstanceMethod (AFD)) {
3428- funcTy = funcTy->getResult ()->getAs <AnyFunctionType>();
3429- }
3430- if (funcTy) {
3431- funcTy = funcTy->removeArgumentLabels (1 )->castTo <AnyFunctionType>();
3414+ if (funcTy)
34323415 addTypeAnnotation (Builder, funcTy, AFD->getGenericSignatureOfContext ());
3433- }
3416+
3417+ return true ;
34343418 }
34353419
34363420 // Implement swift::VisibleDeclConsumer.
@@ -3455,10 +3439,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
34553439 case LookupKind::ValueExpr:
34563440 if (auto *CD = dyn_cast<ConstructorDecl>(D)) {
34573441 // Do we want compound function names here?
3458- if (shouldUseFunctionReference (CD, dynamicLookupInfo)) {
3459- addCompoundFunctionName (CD, Reason, dynamicLookupInfo);
3442+ if (addCompoundFunctionNameIfDesiable (CD, Reason, dynamicLookupInfo))
34603443 return ;
3461- }
34623444
34633445 if (auto MT = ExprType->getAs <AnyMetatypeType>()) {
34643446 Type Ty = MT->getInstanceType ();
@@ -3529,10 +3511,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
35293511 return ;
35303512
35313513 // Do we want compound function names here?
3532- if (shouldUseFunctionReference (FD, dynamicLookupInfo)) {
3533- addCompoundFunctionName (FD, Reason, dynamicLookupInfo);
3514+ if (addCompoundFunctionNameIfDesiable (FD, Reason, dynamicLookupInfo))
35343515 return ;
3535- }
35363516
35373517 addMethodCall (FD, Reason, dynamicLookupInfo);
35383518
0 commit comments