@@ -927,6 +927,7 @@ static CodeCompletionResult::ExpectedTypeRelation calculateTypeRelation(
927927
928928static CodeCompletionResult::ExpectedTypeRelation
929929calculateTypeRelationForDecl (const Decl *D, Type ExpectedType,
930+ bool IsImplicitlyCurriedInstanceMethod,
930931 bool UseFuncResultType = true ) {
931932 auto VD = dyn_cast<ValueDecl>(D);
932933 auto DC = D->getDeclContext ();
@@ -935,7 +936,8 @@ calculateTypeRelationForDecl(const Decl *D, Type ExpectedType,
935936
936937 if (auto FD = dyn_cast<AbstractFunctionDecl>(VD)) {
937938 auto funcType = FD->getType ()->getAs <AnyFunctionType>();
938- if (DC->isTypeContext () && funcType && funcType->is <AnyFunctionType>())
939+ if (DC->isTypeContext () && funcType && funcType->is <AnyFunctionType>() &&
940+ !IsImplicitlyCurriedInstanceMethod)
939941 funcType = funcType->getResult ()->getAs <AnyFunctionType>();
940942 if (funcType) {
941943 auto relation = calculateTypeRelation (funcType, ExpectedType, DC);
@@ -953,12 +955,15 @@ calculateTypeRelationForDecl(const Decl *D, Type ExpectedType,
953955 return calculateTypeRelation (VD->getType (), ExpectedType, DC);
954956}
955957
956- static CodeCompletionResult::ExpectedTypeRelation calculateMaxTypeRelationForDecl (
957- const Decl *D,
958- ArrayRef<Type> ExpectedTypes) {
958+ static CodeCompletionResult::ExpectedTypeRelation
959+ calculateMaxTypeRelationForDecl (
960+ const Decl *D,
961+ ArrayRef<Type> ExpectedTypes,
962+ bool IsImplicitlyCurriedInstanceMethod = false ) {
959963 auto Result = CodeCompletionResult::ExpectedTypeRelation::Unrelated;
960964 for (auto Type : ExpectedTypes) {
961- Result = std::max (Result, calculateTypeRelationForDecl (D, Type));
965+ Result = std::max (Result, calculateTypeRelationForDecl (
966+ D, Type, IsImplicitlyCurriedInstanceMethod));
962967 }
963968 return Result;
964969}
@@ -1645,9 +1650,11 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
16451650 bool shouldUseFunctionReference (AbstractFunctionDecl *D) {
16461651 if (PreferFunctionReferencesToCalls)
16471652 return true ;
1653+ bool isImplicitlyCurriedIM = isImplicitlyCurriedInstanceMethod (D);
16481654 for (auto expectedType : ExpectedTypes) {
16491655 if (expectedType && expectedType->is <AnyFunctionType>() &&
1650- calculateTypeRelationForDecl (D, expectedType, false ) >=
1656+ calculateTypeRelationForDecl (D, expectedType, isImplicitlyCurriedIM,
1657+ /* UseFuncResult=*/ false ) >=
16511658 CodeCompletionResult::ExpectedTypeRelation::Convertible) {
16521659 return true ;
16531660 }
@@ -2338,39 +2345,34 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
23382345 addPattern (/* includeDefaultArgs*/ false );
23392346 addPattern ();
23402347 }
2341-
2342- void addMethodCall (const FuncDecl *FD, DeclVisibilityKind Reason) {
2343- if (FD->getName ().empty ())
2344- return ;
2345- foundFunction (FD);
2346- bool IsImplicitlyCurriedInstanceMethod;
2348+ bool isImplicitlyCurriedInstanceMethod (const AbstractFunctionDecl *FD) {
23472349 switch (Kind) {
23482350 case LookupKind::ValueExpr:
2349- IsImplicitlyCurriedInstanceMethod = ExprType->is <AnyMetatypeType>() &&
2350- !FD->isStatic ();
2351- break ;
2351+ return ExprType->is <AnyMetatypeType>() && !FD->isStatic ();
23522352 case LookupKind::ValueInDeclContext:
2353- IsImplicitlyCurriedInstanceMethod =
2354- InsideStaticMethod &&
2353+ if (InsideStaticMethod &&
23552354 FD->getDeclContext () == CurrentMethod->getDeclContext () &&
2356- !FD->isStatic ();
2357- if (!IsImplicitlyCurriedInstanceMethod) {
2358- if (auto Init = dyn_cast<Initializer>(CurrDeclContext)) {
2359- IsImplicitlyCurriedInstanceMethod =
2360- FD->getDeclContext () == Init->getParent () &&
2361- !FD->isStatic ();
2362- }
2363- }
2364- break ;
2355+ !FD->isStatic ())
2356+ return true ;
2357+ if (auto Init = dyn_cast<Initializer>(CurrDeclContext))
2358+ return FD->getDeclContext () == Init->getParent () && !FD->isStatic ();
2359+ return false ;
23652360 case LookupKind::EnumElement:
23662361 case LookupKind::Type:
23672362 case LookupKind::TypeInDeclContext:
23682363 llvm_unreachable (" cannot have a method call while doing a "
23692364 " type completion" );
23702365 case LookupKind::ImportFromModule:
2371- IsImplicitlyCurriedInstanceMethod = false ;
2372- break ;
2366+ return false ;
23732367 }
2368+ }
2369+
2370+ void addMethodCall (const FuncDecl *FD, DeclVisibilityKind Reason) {
2371+ if (FD->getName ().empty ())
2372+ return ;
2373+ foundFunction (FD);
2374+ bool IsImplicitlyCurriedInstanceMethod =
2375+ isImplicitlyCurriedInstanceMethod (FD);
23742376
23752377 StringRef Name = FD->getName ().get ();
23762378 assert (!Name.empty () && " name should not be empty" );
0 commit comments