Skip to content

Commit e5d8113

Browse files
committed
[CodeCompletion] Pre-remove argument labels from function types
Before checking type relation between candidate types and expected types. In normal compilation, this removal is done in CSGen. However, since code-completion directly uses Constraint System, we have to manually remove argument labels before checking convertibility. We can remove argument labels unconditionally because function types as as value cannot have argument labels. (i.e. `let f: (a: Int) -> Int` is illegal). That means, expected types shouldn't have any argument labels. This fixes regression revealed in 5e75b1a rdar://problem/41496748
1 parent 209d6d9 commit e5d8113

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ calculateTypeRelationForDecl(const Decl *D, Type ExpectedType,
973973
!IsImplicitlyCurriedInstanceMethod)
974974
funcType = funcType->getResult()->getAs<AnyFunctionType>();
975975
if (funcType) {
976+
funcType = funcType->removeArgumentLabels(1)->castTo<AnyFunctionType>();
976977
auto relation = calculateTypeRelation(funcType, ExpectedType, DC);
977978
if (UseFuncResultType)
978979
relation =

test/IDE/complete_func_reference.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ do {
122122
}
123123

124124
// ANY_INT: Begin completions
125-
// ANY_INT-DAG: Decl{{.*}}: anyToInt({#a: Any#})[#Int#]; name=anyToInt(a: Any)
125+
// ANY_INT_DAG: Decl{{.*}}/TypeRelation[Identical]: anyToInt(a:); name=anyToInt(a:)
126126
// ANY_INT-DAG: Decl{{.*}}/NotRecommended/TypeRelation[Invalid]: intToVoid({#a: Int#})[#Void#];
127127
// ANY_INT-DAG: Decl{{.*}}/NotRecommended/TypeRelation[Invalid]: anyToVoid({#a: Any#})[#Void#];
128128
// ANY_INT-DAG: Decl{{.*}}/NotRecommended/TypeRelation[Invalid]: voidToVoid()[#Void#];
@@ -135,7 +135,7 @@ do {
135135
// ANY_INT: End completions
136136

137137
// ANY_INT_STATIC_CURRY: Begin completions
138-
// ANY_INT_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal: anyToInt({#self: S0#})[#(a: Any) -> Int#]; name=anyToInt(S0)
138+
// ANY_INT_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Identical]: anyToInt({#self: S0#})[#(a: Any) -> Int#];
139139
// ANY_INT_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended/TypeRelation[Invalid]: voidToVoid({#self: S0#})[#() -> Void#];
140140
// ANY_INT_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended/TypeRelation[Invalid]: intToVoid({#self: S0#})[#(a: Int) -> Void#];
141141
// ANY_INT_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended/TypeRelation[Invalid]: anyToVoid({#self: S0#})[#(a: Any) -> Void#];
@@ -153,25 +153,25 @@ do {
153153
}
154154

155155
// INT_ANY: Begin completions
156-
// INT_ANY-DAG: Decl{{.*}}: intToAny({#a: Int#})[#Any#]; name=intToAny(a: Int)
157-
// INT_ANY-DAG: Decl{{.*}}: intToInt({#a: Int#})[#Int#]; name=intToInt(a: Int)
158-
// INT_ANY-DAG: Decl{{.*}}: intToVoid({#a: Int#})[#Void#]; name=intToVoid(a: Int)
159-
// INT_ANY-DAG: Decl{{.*}}: anyToAny({#a: Any#})[#Any#]; name=anyToAny(a: Any)
160-
// INT_ANY-DAG: Decl{{.*}}: anyToInt({#a: Any#})[#Int#]; name=anyToInt(a: Any)
161-
// INT_ANY-DAG: Decl{{.*}}: anyToVoid({#a: Any#})[#Void#]; name=anyToVoid(a: Any)
156+
// INT_ANY-DAG: Decl{{.*}}/TypeRelation[Identical]: intToAny(a:);
157+
// INT_ANY-DAG: Decl{{.*}}/TypeRelation[Convertible]: intToInt(a:);
158+
// INT_ANY-DAG: Decl{{.*}}/TypeRelation[Convertible]: intToVoid(a:);
159+
// INT_ANY-DAG: Decl{{.*}}/TypeRelation[Convertible]: anyToAny(a:);
160+
// INT_ANY-DAG: Decl{{.*}}/TypeRelation[Convertible]: anyToInt(a:);
161+
// INT_ANY-DAG: Decl{{.*}}/TypeRelation[Convertible]: anyToVoid(a:);
162162
// INT_ANY-DAG: Decl{{.*}}/TypeRelation[Convertible]: returnsIntToInt()[#(Int) -> Int#];
163163
// INT_ANY-DAG: Decl{{.*}}/NotRecommended/TypeRelation[Invalid]: voidToVoid()[#Void#];
164164
// INT_ANY-DAG: Decl{{.*}}: voidToInt()[#Int#];
165165
// INT_ANY-DAG: Decl{{.*}}: voidToAny()[#Any#];
166166
// INT_ANY: End completions
167167

168168
// INT_ANY_STATIC_CURRY: Begin completions
169-
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal: intToInt({#self: S0#})[#(a: Int) -> Int#]; name=intToInt(S0)
170-
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended/TypeRelation[Invalid]: intToVoid({#self: S0#})[#(a: Int) -> Void#]; name=intToVoid(S0)
171-
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal: anyToAny({#self: S0#})[#(a: Any) -> Any#]; name=anyToAny(S0)
172-
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended/TypeRelation[Invalid]: anyToVoid({#self: S0#})[#(a: Any) -> Void#]; name=anyToVoid(S0)
173-
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal: intToAny({#self: S0#})[#(a: Int) -> Any#]; name=intToAny(S0)
174-
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal: anyToInt({#self: S0#})[#(a: Any) -> Int#]; name=anyToInt(S0)
169+
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: intToInt({#self: S0#})[#(a: Int) -> Int#];
170+
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: intToVoid({#self: S0#})[#(a: Int) -> Void#];
171+
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: anyToAny({#self: S0#})[#(a: Any) -> Any#];
172+
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: anyToVoid({#self: S0#})[#(a: Any) -> Void#];
173+
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Identical]: intToAny({#self: S0#})[#(a: Int) -> Any#];
174+
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: anyToInt({#self: S0#})[#(a: Any) -> Int#];
175175
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: returnsIntToInt({#self: S0#})[#() -> (Int) -> Int#];
176176
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal: voidToAny({#self: S0#})[#() -> Any#];
177177
// INT_ANY_STATIC_CURRY-DAG: Decl[InstanceMethod]/CurrNominal: voidToInt({#self: S0#})[#() -> Int#];

0 commit comments

Comments
 (0)