Skip to content

Commit 63eb78b

Browse files
committed
[IDE] Fix code-completion fallout after changes for SE-0111.
rdar://27642873
1 parent 071a669 commit 63eb78b

7 files changed

+51
-26
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,8 +2225,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
22252225
Builder.addComma();
22262226
if (BodyParams) {
22272227
// If we have a local name for the parameter, pass in that as well.
2228-
auto name = BodyParams->get(i)->getName();
2229-
Builder.addCallParameter(Name, name, ParamType, TupleElt.isVararg(),
2228+
auto argName = BodyParams->get(i)->getArgumentName();
2229+
auto bodyName = BodyParams->get(i)->getName();
2230+
Builder.addCallParameter(argName, bodyName, ParamType, TupleElt.isVararg(),
22302231
true);
22312232
} else {
22322233
Builder.addCallParameter(Name, ParamType, TupleElt.isVararg(), true);
@@ -2244,8 +2245,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
22442245

22452246
modifiedBuilder = true;
22462247
if (BodyParams) {
2247-
auto name = BodyParams->get(0)->getName();
2248-
Builder.addCallParameter(Identifier(), name, T,
2248+
auto argName = BodyParams->get(0)->getArgumentName();
2249+
auto bodyName = BodyParams->get(0)->getName();
2250+
Builder.addCallParameter(argName, bodyName, T,
22492251
/*IsVarArg*/false, true);
22502252
} else
22512253
Builder.addCallParameter(Identifier(), T, /*IsVarArg*/false, true);
@@ -2319,7 +2321,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
23192321

23202322
void addFunctionCallPattern(const AnyFunctionType *AFT,
23212323
const AbstractFunctionDecl *AFD = nullptr) {
2322-
foundFunction(AFT);
2324+
if (AFD)
2325+
foundFunction(AFD);
2326+
else
2327+
foundFunction(AFT);
23232328

23242329
// Add the pattern, possibly including any default arguments.
23252330
auto addPattern = [&](bool includeDefaultArgs = true) {

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,35 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
16441644
auto topLocator = cs.getConstraintLocator(semanticExpr);
16451645
referencedDecl = solution.resolveLocatorToDecl(topLocator);
16461646

1647+
if (!referencedDecl.getDecl()) {
1648+
// Do another check in case we have a curried call from binding a function
1649+
// reference to a variable, for example:
1650+
//
1651+
// class C {
1652+
// func instanceFunc(p1: Int, p2: Int) {}
1653+
// }
1654+
// func t(c: C) {
1655+
// C.instanceFunc(c)#^COMPLETE^#
1656+
// }
1657+
//
1658+
// We need to get the referenced function so we can complete the argument
1659+
// labels. (Note that the requirement to have labels in the curried call
1660+
// seems inconsistent with the removal of labels from function types.
1661+
// If this changes the following code could be removed).
1662+
if (auto *CE = dyn_cast<CallExpr>(semanticExpr)) {
1663+
if (auto *UDE = dyn_cast<UnresolvedDotExpr>(CE->getFn())) {
1664+
if (isa<TypeExpr>(UDE->getBase())) {
1665+
auto udeLocator = cs.getConstraintLocator(UDE);
1666+
auto udeRefDecl = solution.resolveLocatorToDecl(udeLocator);
1667+
if (auto *FD = dyn_cast_or_null<FuncDecl>(udeRefDecl.getDecl())) {
1668+
if (FD->isInstanceMember())
1669+
referencedDecl = udeRefDecl;
1670+
}
1671+
}
1672+
}
1673+
}
1674+
}
1675+
16471676
// Recover the original type if needed.
16481677
recoverOriginalType();
16491678
return exprType;

test/IDE/complete_call_arg.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// REQUIRES: se_0111_complete
2-
31
// RUN-FIXME: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ARG1 | FileCheck %s -check-prefix=EXPECT_OINT
42
// RUN-FIXME: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ARG2 | FileCheck %s -check-prefix=ARG-NAME1
53
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ARG3 | FileCheck %s -check-prefix=ARG-NAME2

test/IDE/complete_default_arguments.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// REQUIRES: se_0111_complete
2-
31
// RUN: sed -n -e '1,/NO_ERRORS_UP_TO_HERE$/ p' %s > %t_no_errors.swift
42
// RUN: %target-swift-frontend -verify -parse %t_no_errors.swift
53

@@ -70,7 +68,7 @@ func testDefaultArgs2() {
7068
}
7169
// DEFAULT_ARGS_2: Begin completions
7270
// DEFAULT_ARGS_2-DAG: Pattern/ExprSpecific: ({#(a): Int#})[#Void#]{{; name=.+$}}
73-
// DEFAULT_ARGS_2-DAG: Pattern/ExprSpecific: ({#(a): Int#}, {#(b): Int#})[#Void#]{{; name=.+$}}
71+
// DEFAULT_ARGS_2-DAG: Pattern/ExprSpecific: ({#(a): Int#}, {#b: Int#})[#Void#]{{; name=.+$}}
7472
// DEFAULT_ARGS_2: End completions
7573

7674
func testDefaultArgs3() {

test/IDE/complete_from_stdlib.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// REQUIRES: se_0111_complete
2-
31
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PLAIN_TOP_LEVEL_1 > %t.toplevel.txt
42
// RUN: FileCheck %s -check-prefix=PLAIN_TOP_LEVEL < %t.toplevel.txt
53
// RUN: FileCheck %s -check-prefix=NO_STDLIB_PRIVATE < %t.toplevel.txt
@@ -151,7 +149,8 @@ func testArchetypeReplacement2<BAR : Equatable>(_ a: [BAR]) {
151149
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/Super: enumerated()[#EnumeratedSequence<[Equatable]>#]{{; name=.+}}
152150
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/Super: min({#by: (Equatable, Equatable) throws -> Bool##(Equatable, Equatable) throws -> Bool#})[' rethrows'][#Equatable?#]{{; name=.+}}
153151
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/Super: max({#by: (Equatable, Equatable) throws -> Bool##(Equatable, Equatable) throws -> Bool#})[' rethrows'][#Equatable?#]{{; name=.+}}
154-
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/Super: reduce({#(initialResult): Result#}, {#(nextPartialResult): (partialResult: Result, Equatable) throws -> Result##(partialResult: Result, Equatable) throws -> Result#})[' rethrows'][#Result#]{{; name=.+}}
152+
// FIXME: The following should include 'partialResult' as local parameter name: "(nextPartialResult): (_ partialResult: Result, Equatable)"
153+
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/Super: reduce({#(initialResult): Result#}, {#(nextPartialResult): (Result, Equatable) throws -> Result##(Result, Equatable) throws -> Result#})[' rethrows'][#Result#]{{; name=.+}}
155154
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/Super: dropFirst({#(n): Int#})[#ArraySlice<Equatable>#]{{; name=.+}}
156155
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/Super: flatMap({#(transform): (Equatable) throws -> Sequence##(Equatable) throws -> Sequence#})[' rethrows'][#[SegmentOfResult.Iterator.Element]#]{{; name=.+}}
157156

@@ -161,7 +160,7 @@ func testArchetypeReplacement3 (_ a : [Int]) {
161160

162161
// PRIVATE_NOMINAL_MEMBERS_7: Begin completions
163162
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/CurrNominal: append({#(newElement): Int#})[#Void#]
164-
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/CurrNominal: removeLast()[#Int#]
163+
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: removeLast()[#Int#]
165164
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/CurrNominal: popLast()[#Int?#]
166165
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceVar]/Super: first[#Int?#]
167166
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: map({#(transform): (Int) throws -> T##(Int) throws -> T#})[' rethrows'][#[T]#]

test/IDE/complete_value_expr.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// REQUIRES: se_0111_complete
2-
31
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FOO_OBJECT_DOT_1 | FileCheck %s -check-prefix=FOO_OBJECT_DOT
42
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FOO_OBJECT_DOT_2 | FileCheck %s -check-prefix=FOO_OBJECT_DOT
53
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FOO_OBJECT_DOT_3 | FileCheck %s -check-prefix=FOO_OBJECT_DOT
@@ -505,27 +503,27 @@ func testImplicitlyCurriedFunc(_ fs: inout FooStruct) {
505503

506504
FooStruct.instanceFunc1(&fs)#^IMPLICITLY_CURRIED_FUNC_1^#
507505
// IMPLICITLY_CURRIED_FUNC_1: Begin completions
508-
// IMPLICITLY_CURRIED_FUNC_1-NEXT: Pattern/ExprSpecific: ({#Int#})[#Void#]{{; name=.+$}}
506+
// IMPLICITLY_CURRIED_FUNC_1-NEXT: Pattern/ExprSpecific: ({#(a): Int#})[#Void#]{{; name=.+$}}
509507
// IMPLICITLY_CURRIED_FUNC_1-NEXT: End completions
510508

511509
FooStruct.instanceFunc2(&fs)#^IMPLICITLY_CURRIED_FUNC_2^#
512510
// IMPLICITLY_CURRIED_FUNC_2: Begin completions
513-
// IMPLICITLY_CURRIED_FUNC_2-NEXT: Pattern/ExprSpecific: ({#Int#}, {#b: &Double#})[#Void#]{{; name=.+$}}
511+
// IMPLICITLY_CURRIED_FUNC_2-NEXT: Pattern/ExprSpecific: ({#(a): Int#}, {#b: &Double#})[#Void#]{{; name=.+$}}
514512
// IMPLICITLY_CURRIED_FUNC_2-NEXT: End completions
515513

516514
FooStruct.varargInstanceFunc0(&fs)#^IMPLICITLY_CURRIED_VARARG_FUNC_0^#
517515
// IMPLICITLY_CURRIED_VARARG_FUNC_0: Begin completions
518-
// IMPLICITLY_CURRIED_VARARG_FUNC_0-NEXT: Pattern/ExprSpecific: ({#Int...#})[#Void#]{{; name=.+$}}
516+
// IMPLICITLY_CURRIED_VARARG_FUNC_0-NEXT: Pattern/ExprSpecific: ({#(v): Int...#})[#Void#]{{; name=.+$}}
519517
// IMPLICITLY_CURRIED_VARARG_FUNC_0-NEXT: End completions
520518

521519
FooStruct.varargInstanceFunc1(&fs)#^IMPLICITLY_CURRIED_VARARG_FUNC_1^#
522520
// IMPLICITLY_CURRIED_VARARG_FUNC_1: Begin completions
523-
// IMPLICITLY_CURRIED_VARARG_FUNC_1-NEXT: Pattern/ExprSpecific: ({#Float#}, {#v: Int...#})[#Void#]{{; name=.+$}}
521+
// IMPLICITLY_CURRIED_VARARG_FUNC_1-NEXT: Pattern/ExprSpecific: ({#(a): Float#}, {#v: Int...#})[#Void#]{{; name=.+$}}
524522
// IMPLICITLY_CURRIED_VARARG_FUNC_1-NEXT: End completions
525523

526524
FooStruct.varargInstanceFunc2(&fs)#^IMPLICITLY_CURRIED_VARARG_FUNC_2^#
527525
// IMPLICITLY_CURRIED_VARARG_FUNC_2: Begin completions
528-
// IMPLICITLY_CURRIED_VARARG_FUNC_2-NEXT: Pattern/ExprSpecific: ({#Float#}, {#b: Double#}, {#v: Int...#})[#Void#]{{; name=.+$}}
526+
// IMPLICITLY_CURRIED_VARARG_FUNC_2-NEXT: Pattern/ExprSpecific: ({#(a): Float#}, {#b: Double#}, {#v: Int...#})[#Void#]{{; name=.+$}}
529527
// IMPLICITLY_CURRIED_VARARG_FUNC_2-NEXT: End completions
530528

531529
// This call is ambiguous, and the expression is invalid.
@@ -798,7 +796,7 @@ func testInsideFunctionCallOnClassInstance1(_ a: FooClass) {
798796

799797
class FuncTypeVars {
800798
var funcVar1: () -> Double
801-
var funcVar2: (a: Int) -> Double
799+
var funcVar2: (a: Int) -> Double // adding the label is erroneous.
802800
}
803801

804802
var funcTypeVarsObject: FuncTypeVars
@@ -811,8 +809,8 @@ func testFuncTypeVars() {
811809

812810
funcTypeVarsObject.funcVar2#^VF2^#
813811
// VF2: Begin completions
814-
// VF2-NEXT: Pattern/ExprSpecific: ({#a: Int#})[#Double#]{{; name=.+$}}
815-
// VF2-NEXT: BuiltinOperator/None: = {#(a: Int) -> Double##(a: Int) -> Double#}[#Void#]
812+
// VF2-NEXT: Pattern/ExprSpecific: ({#Int#})[#Double#]{{; name=.+$}}
813+
// VF2-NEXT: BuiltinOperator/None: = {#(Int) -> Double##(Int) -> Double#}[#Void#]
816814
// VF2-NEXT: End completions
817815
}
818816

test/IDE/complete_vararg.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// REQUIRES: se_0111_complete
2-
31
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_1 | FileCheck %s -check-prefix=TOP_LEVEL_1
42
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OBJ_DOT_1 | FileCheck %s -check-prefix=OBJ_DOT_1
53
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FREE_FUNC_1 | FileCheck %s -check-prefix=FREE_FUNC_1

0 commit comments

Comments
 (0)