Skip to content

Commit 131e35e

Browse files
authored
Merge pull request swiftlang#5515 from benlangmuir/cc-func-ref-opt
2 parents 1a59321 + 32f131e commit 131e35e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
16521652
return true;
16531653
bool isImplicitlyCurriedIM = isImplicitlyCurriedInstanceMethod(D);
16541654
for (auto expectedType : ExpectedTypes) {
1655-
if (expectedType && expectedType->is<AnyFunctionType>() &&
1655+
if (expectedType &&
1656+
expectedType->lookThroughAllAnyOptionalTypes()
1657+
->is<AnyFunctionType>() &&
16561658
calculateTypeRelationForDecl(D, expectedType, isImplicitlyCurriedIM,
16571659
/*UseFuncResult=*/false) >=
16581660
CodeCompletionResult::ExpectedTypeRelation::Convertible) {

test/IDE/complete_func_reference.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ANY_INT_2 > %t.results
99
// RUN:%FileCheck %s -check-prefix=ANY_INT < %t.results
1010
// RUN:%FileCheck %s -check-prefix=ANY_INT_STATIC_CURRY < %t.results
11+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ANY_INT_3 | %FileCheck %s -check-prefix=ANY_INT
12+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ANY_INT_4 | %FileCheck %s -check-prefix=ANY_INT
1113
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INT_ANY_0 | %FileCheck %s -check-prefix=INT_ANY
1214
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INT_ANY_1 | %FileCheck %s -check-prefix=INT_ANY
1315
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INT_ANY_2 > %t.results
1416
// RUN: %FileCheck %s -check-prefix=INT_ANY < %t.results
1517
// RUN: %FileCheck %s -check-prefix=INT_ANY_STATIC_CURRY < %t.results
18+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INT_ANY_3 > %t.results
1619
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=VOID_INT_INT_0 | %FileCheck %s -check-prefix=VOID_INT_INT
1720
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=VOID_INT_INT_1 | %FileCheck %s -check-prefix=VOID_INT_INT
1821
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=VOID_INT_INT_2 | %FileCheck %s -check-prefix=VOID_INT_INT
@@ -109,6 +112,14 @@ do {
109112
func take(_: @escaping (Any)->Int) {}
110113
take(S0.#^ANY_INT_2^#)
111114
}
115+
do {
116+
func take(_: @escaping ((Any)->Int)???!) {}
117+
take(S0().#^ANY_INT_3^#)
118+
}
119+
do {
120+
let take: ((Any)->Int)?
121+
take = S0().#^ANY_INT_4^#
122+
}
112123

113124
// ANY_INT: Begin completions
114125
// ANY_INT-DAG: Decl{{.*}}/TypeRelation[Convertible]: anyToInt(a:);
@@ -174,6 +185,10 @@ do {
174185
func take(_: @escaping (Int)->Any) {}
175186
take(S0.#^INT_ANY_2^#)
176187
}
188+
do {
189+
func take(_: @escaping ((Int)->Any)?) {}
190+
take(S0.#^INT_ANY_3^#)
191+
}
177192

178193
do {
179194
func take(_: @escaping ()->(Int)->Int) {}

0 commit comments

Comments
 (0)