Skip to content

Commit b179953

Browse files
committed
[CodeCompletion] Be lenient in callee analysis
Accept `getInterfaceType->hasError()` declarations. Even if the part of the declaration has error, we still have chance to get context info from the other part of it. For instance: func foo(x: Int, y: INt) { } foo(x: #^COMPLETE^# We should resolve 'Int' as the context type even if parameter `y` is an error type. (cherry picked from commit 337d53f)
1 parent 2fe89a6 commit b179953

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5115,12 +5115,13 @@ void collectPossibleCalleesByQualifiedLookup(
51155115
Type declaredMemberType = VD->getInterfaceType();
51165116
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(VD))
51175117
if (AFD->getDeclContext()->isTypeContext())
5118-
declaredMemberType = AFD->getMethodInterfaceType();
5118+
declaredMemberType =
5119+
declaredMemberType->castTo<AnyFunctionType>()->getResult();
51195120

51205121
auto fnType =
51215122
baseTy->getTypeOfMember(DC.getParentModule(), VD, declaredMemberType);
51225123

5123-
if (!fnType || fnType->hasError())
5124+
if (!fnType)
51245125
continue;
51255126
if (auto *AFT = fnType->getAs<AnyFunctionType>()) {
51265127
candidates.emplace_back(AFT, VD);

test/IDE/complete_call_arg.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OVERLOAD6 | %FileCheck %s -check-prefix=OVERLOAD6
1616
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OVERLOAD7 | %FileCheck %s -check-prefix=OVERLOAD6
1717

18+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=HASERROR1 | %FileCheck %s -check-prefix=HASERROR1
19+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=HASERROR2 | %FileCheck %s -check-prefix=HASERROR2
20+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=HASERROR3 | %FileCheck %s -check-prefix=HASERROR3
21+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=HASERROR4 | %FileCheck %s -check-prefix=HASERROR4
22+
1823
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=MEMBER1 | %FileCheck %s -check-prefix=MEMBER1
1924
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=MEMBER2 | %FileCheck %s -check-prefix=MEMBER2
2025
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=MEMBER3 | %FileCheck %s -check-prefix=MEMBER3
@@ -280,6 +285,35 @@ class C3 {
280285
// OVERLOAD6-DAG: Decl[InstanceVar]/CurrNominal: C2I[#C2#]; name=C2I
281286
// OVERLOAD6: End completions
282287

288+
extension C3 {
289+
func hasError(a1: C1, b1: TypeInvalid) -> Int {}
290+
291+
func f7(obj: C3) {
292+
let _ = obj.hasError(#^HASERROR1^#
293+
let _ = obj.hasError(a1: #^HASERROR2^#
294+
let _ = obj.hasError(a1: IC1, #^HASERROR3^#
295+
let _ = obj.hasError(a1: IC1, b1: #^HASERROR4^#
296+
}
297+
}
298+
299+
// HASERROR1: Begin completions
300+
// HASERROR1-DAG: Pattern/CurrModule: ['(']{#a1: C1#}, {#b1: <<error type>>#}[')'][#Int#];
301+
// HASERROR1: End completions
302+
303+
// HASERROR2: Begin completions
304+
// HASERROR2-DAG: Decl[InstanceVar]/CurrNominal/TypeRelation[Identical]: C1I[#C1#];
305+
// HASERROR2-DAG: Decl[InstanceVar]/CurrNominal: C2I[#C2#];
306+
// HASERROR2: End completions
307+
308+
// HASERROR3: Begin completions
309+
// HASERROR3-DAG: Keyword/ExprSpecific: b1: [#Argument name#];
310+
// HASERROR3: End completions
311+
312+
// HASERROR4: Begin completions
313+
// HASERROR4-DAG: Decl[InstanceVar]/CurrNominal: C1I[#C1#];
314+
// HASERROR4-DAG: Decl[InstanceVar]/CurrNominal: C2I[#C2#];
315+
// HASERROR4: End completions
316+
283317
class C4 {
284318
func f1(_ G : Gen) {
285319
foo(1, b1: G.#^MEMBER1^#

0 commit comments

Comments
 (0)