@@ -1858,35 +1858,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
1858
1858
Builder.addDeclDocCommentWords (llvm::makeArrayRef (Pairs));
1859
1859
}
1860
1860
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
-
1890
1861
// / Returns \c true if \p TAD is usable as a first type of a requirement in
1891
1862
// / \c where clause for a context.
1892
1863
// / \p selfTy must be a \c Self type of the context.
@@ -3388,9 +3359,27 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3388
3359
}
3389
3360
3390
3361
// / 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
+
3394
3383
CommandWordsPairs Pairs;
3395
3384
CodeCompletionResultBuilder Builder (
3396
3385
Sink, CodeCompletionResult::ResultKind::Declaration,
@@ -3422,15 +3411,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3422
3411
Builder.addRightParen ();
3423
3412
}
3424
3413
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)
3432
3415
addTypeAnnotation (Builder, funcTy, AFD->getGenericSignatureOfContext ());
3433
- }
3416
+
3417
+ return true ;
3434
3418
}
3435
3419
3436
3420
// Implement swift::VisibleDeclConsumer.
@@ -3455,10 +3439,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3455
3439
case LookupKind::ValueExpr:
3456
3440
if (auto *CD = dyn_cast<ConstructorDecl>(D)) {
3457
3441
// Do we want compound function names here?
3458
- if (shouldUseFunctionReference (CD, dynamicLookupInfo)) {
3459
- addCompoundFunctionName (CD, Reason, dynamicLookupInfo);
3442
+ if (addCompoundFunctionNameIfDesiable (CD, Reason, dynamicLookupInfo))
3460
3443
return ;
3461
- }
3462
3444
3463
3445
if (auto MT = ExprType->getAs <AnyMetatypeType>()) {
3464
3446
Type Ty = MT->getInstanceType ();
@@ -3529,10 +3511,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3529
3511
return ;
3530
3512
3531
3513
// Do we want compound function names here?
3532
- if (shouldUseFunctionReference (FD, dynamicLookupInfo)) {
3533
- addCompoundFunctionName (FD, Reason, dynamicLookupInfo);
3514
+ if (addCompoundFunctionNameIfDesiable (FD, Reason, dynamicLookupInfo))
3534
3515
return ;
3535
- }
3536
3516
3537
3517
addMethodCall (FD, Reason, dynamicLookupInfo);
3538
3518
0 commit comments