Skip to content

Commit 8d63f29

Browse files
committed
[CodeCompletion] Don't suggest argument labels from unapplicable overload
When matching an argument to a parameter list, if there is no matching parameter, the argument list is not applicable to the parameters. In such case, code completion should not suggest argument labels of the function. rdar://77867723
1 parent 1f005e1 commit 8d63f29

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,9 @@ static bool getPositionInParams(DeclContext &DC, Expr *Args, Expr *CCExpr,
847847
}
848848

849849
if (!AdvancedPosInParams) {
850-
// We haven't performed any special advance logic. Assume the argument
851-
// and parameter match, so advance PosInParams by 1.
852-
++PosInParams;
850+
// If there is no matching argument label. These arguments can't be
851+
// applied to the params.
852+
return false;
853853
}
854854
}
855855
if (PosInArgs < tuple->getNumElements() && PosInParams < Params.size()) {

test/IDE/complete_call_arg.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,3 +933,16 @@ func testGenericConstructor() {
933933
// GENERIC_INITIALIZER-DAG: Pattern/ExprSpecific: {#text: String#}[#String#]
934934
// GENERIC_INITIALIZER: End completions
935935
}
936+
937+
struct Rdar77867723 {
938+
enum Horizontal { case east, west }
939+
enum Vertical { case up, down }
940+
func fn(aaa: Horizontal = .east, bbb: Vertical = .up) {}
941+
func fn(ccc: Vertical = .up, ddd: Horizontal = .west) {}
942+
func test {
943+
self.fn(ccc: .up, #^OVERLOAD_LABEL^#)
944+
// OVERLOAD_LABEL: Begin completions, 1 items
945+
// OVERLOAD_LABEL-DAG: Pattern/ExprSpecific: {#ddd: Horizontal#}[#Horizontal#];
946+
// OVERLOAD_LABEL: End completions
947+
}
948+
}

test/SourceKit/CodeComplete/complete_type_match.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,32 @@ func takeIntOpt(x: Int, y: Int?)
1414
func takeString(x: Int, y: String)
1515
func takeAny(x: Int, y: Any)
1616

17-
takeInt(1, y: #^TOP_LEVEL_0^#)
17+
takeInt(x: 1, y: #^TOP_LEVEL_0^#)
1818
// TOP_LEVEL_0-NOT: nil
1919
// TOP_LEVEL_0: valueZ
2020
// TOP_LEVEL_0: Int
2121
// TOP_LEVEL_0: valueA
2222
// TOP_LEVEL_0: valueS
2323

24-
takeString(1, y: #^TOP_LEVEL_1^#)
24+
takeString(x: 1, y: #^TOP_LEVEL_1^#)
2525
// TOP_LEVEL_1: valueS
2626
// TOP_LEVEL_1: String
2727
// TOP_LEVEL_1: valueA
2828
// TOP_LEVEL_1: valueZ
2929

30-
takeAny(1, y: #^TOP_LEVEL_2^#)
30+
takeAny(x: 1, y: #^TOP_LEVEL_2^#)
3131
// TOP_LEVEL_2: valueA
3232
// TOP_LEVEL_2: valueS
3333
// TOP_LEVEL_2: valueZ
3434

35-
takeIntOpt(1, y: #^TOP_LEVEL_3^#)
35+
takeIntOpt(x: 1, y: #^TOP_LEVEL_3^#)
3636
// TOP_LEVEL_3: nil
3737
// TOP_LEVEL_3: valueZ
3838
// TOP_LEVEL_3: valueA
3939
// TOP_LEVEL_3: valueS
4040

4141
func testCrossContext(x: Int, y: String, z: Any) {
42-
takeInt(1, y: #^CROSS_CONTEXT_0^#)
42+
takeInt(x: 1, y: #^CROSS_CONTEXT_0^#)
4343
}
4444
// CROSS_CONTEXT_0: x
4545
// CROSS_CONTEXT_0: valueZ
@@ -56,7 +56,7 @@ struct FromMethod {
5656
}
5757

5858
func testFromMethod(x: FromMethod) {
59-
takeInt(1, y: x.#^FROM_METHOD_0^#)
59+
takeInt(x: 1, y: x.#^FROM_METHOD_0^#)
6060
}
6161
// FROM_METHOD_0: valueZ()
6262
// FROM_METHOD_0: valueA()

0 commit comments

Comments
 (0)