Skip to content

Commit 1046516

Browse files
authored
Merge pull request swiftlang#30310 from rintaro/ide-completion-typeexprcall-rdar53516588
[CodeCompletion] Re-typecheck TypeExpr without call arguments
2 parents e86558f + 8f7340c commit 1046516

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ static void collectPossibleCalleesByQualifiedLookup(
351351
DeclContext &DC, Expr *baseExpr, DeclNameRef name,
352352
SmallVectorImpl<FunctionTypeAndDecl> &candidates) {
353353
ConcreteDeclRef ref = nullptr;
354+
355+
// Re-typecheck TypeExpr so it's typechecked without the arguments which may
356+
// affects the inference of the generic arguments.
357+
if (TypeExpr *tyExpr = dyn_cast<TypeExpr>(baseExpr)) {
358+
tyExpr->setType(nullptr);
359+
tyExpr->getTypeLoc().setType(nullptr);
360+
}
361+
354362
auto baseTyOpt = getTypeOfCompletionContextExpr(
355363
DC.getASTContext(), &DC, CompletionTypeCheckKind::Normal, baseExpr, ref);
356364
if (!baseTyOpt)
@@ -435,7 +443,7 @@ static bool collectPossibleCalleesForApply(
435443
auto baseTy = AMT->getInstanceType();
436444
if (isa<TypeExpr>(fnExpr) && baseTy->mayHaveMembers()) {
437445
collectPossibleCalleesByQualifiedLookup(
438-
DC, AMT, DeclNameRef::createConstructor(), candidates);
446+
DC, fnExpr, DeclNameRef::createConstructor(), candidates);
439447
}
440448
}
441449

test/IDE/complete_call_arg.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ARCHETYPE_GENERIC_1 | %FileCheck %s -check-prefix=ARCHETYPE_GENERIC_1
9595
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PARAM_WITH_ERROR_AUTOCLOSURE| %FileCheck %s -check-prefix=PARAM_WITH_ERROR_AUTOCLOSURE
9696
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TYPECHECKED_OVERLOADED | %FileCheck %s -check-prefix=TYPECHECKED_OVERLOADED
97+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TYPECHECKED_TYPEEXPR | %FileCheck %s -check-prefix=TYPECHECKED_TYPEEXPR
9798

9899
var i1 = 1
99100
var i2 = 2
@@ -753,16 +754,28 @@ struct TestHasErrorAutoclosureParam {
753754
}
754755
}
755756

756-
struct MyType {
757+
struct MyType<T> {
758+
init(arg1: String, arg2: T) {}
757759
func overloaded() {}
758760
func overloaded(_ int: Int) {}
759761
func overloaded(name: String, value: String) {}
760762
}
761-
func testTypecheckedOverloaded(value: MyType) {
763+
func testTypecheckedOverloaded<T>(value: MyType<T>) {
762764
value.overloaded(#^TYPECHECKED_OVERLOADED^#)
763765
// TYPECHECKED_OVERLOADED: Begin completions
764766
// TYPECHECKED_OVERLOADED-DAG: Decl[InstanceMethod]/CurrNominal: ['('][')'][#Void#];
765767
// TYPECHECKED_OVERLOADED-DAG: Decl[InstanceMethod]/CurrNominal: ['(']{#(int): Int#}[')'][#Void#];
766768
// TYPECHECKED_OVERLOADED-DAG: Decl[InstanceMethod]/CurrNominal: ['(']{#name: String#}, {#value: String#}[')'][#Void#];
767769
// TYPECHECKED_OVERLOADED: End completions
768770
}
771+
772+
extension MyType where T == Int {
773+
init(_ intVal: T) {}
774+
}
775+
func testTypecheckedTypeExpr() {
776+
MyType(#^TYPECHECKED_TYPEEXPR^#
777+
}
778+
// TYPECHECKED_TYPEEXPR: Begin completions
779+
// TYPECHECKED_TYPEEXPR: Decl[Constructor]/CurrNominal: ['(']{#arg1: String#}, {#arg2: _#}[')'][#MyType<_>#]; name=arg1: String, arg2: _
780+
// TYPECHECKED_TYPEEXPR: Decl[Constructor]/CurrNominal: ['(']{#(intVal): Int#}[')'][#MyType<Int>#]; name=intVal: Int
781+
// TYPECHECKED_TYPEEXPR: End completions

0 commit comments

Comments
 (0)