Skip to content

Commit e053dab

Browse files
authored
Merge pull request #13696 from benlangmuir/cc-autoclosure-trailing-closure
[code-complete] Don't suggest trailing closure for autoclosure
2 parents 079efad + e44eb34 commit e053dab

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,9 +1546,14 @@ static bool hasTrivialTrailingClosure(const FuncDecl *FD,
15461546
OneArg = (NonDefault == 0);
15471547
}
15481548

1549-
if (OneArg)
1550-
if (auto Fn = funcType->getParams().back().getType()->getAs<AnyFunctionType>())
1551-
return Fn->getInput()->isVoid() && Fn->getResult()->isVoid();
1549+
if (OneArg) {
1550+
auto param = funcType->getParams().back();
1551+
if (!param.isAutoClosure()) {
1552+
if (auto Fn = param.getType()->getAs<AnyFunctionType>()) {
1553+
return Fn->getInput()->isVoid() && Fn->getResult()->isVoid();
1554+
}
1555+
}
1556+
}
15521557

15531558
return false;
15541559
}

test/IDE/complete_trailing_closure.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ struct S {
5757
func method1(_: ()->()) {}
5858
static func method2(_: ()->()) {}
5959
func nonTrivial1(_: (Int)->()) {}
60+
func nonTrivial2(_: @autoclosure ()->()) {}
6061
func test2() {
6162
self.#^METHOD_1^#
6263
}
6364
// METHOD_1: Begin completions
6465
// METHOD_1: Decl[InstanceMethod]/CurrNominal: method1 {|}[#Void#]
6566
// METHOD_1: Decl[InstanceMethod]/CurrNominal: method1({#() -> ()##() -> ()#})[#Void#]
6667
// METHOD_1: Decl[InstanceMethod]/CurrNominal: nonTrivial1({#(Int) -> ()##(Int) -> ()#})[#Void#]
68+
// METHOD_1: Decl[InstanceMethod]/CurrNominal: nonTrivial2({#()#})[#Void#]
6769
// METHOD_1: End completions
6870

6971
func test3() {
@@ -85,6 +87,7 @@ class C {
8587
func method1(_: ()->()) {}
8688
class func method2(_: ()->()) {}
8789
func nonTrivial1(_: (Int)->()) {}
90+
func nonTrivial2(_: @autoclosure ()->()) {}
8891
func test6() {
8992
self.#^METHOD_4^#
9093
}

0 commit comments

Comments
 (0)