Skip to content

Commit 53be298

Browse files
authored
[IDE] Don't emit “Convert to Trailing Closure” for trailing closure (#15824)
rdar://problem/39253640
1 parent bd3e488 commit 53be298

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,6 +2695,10 @@ static CallExpr *findTrailingClosureTarget(SourceManager &SM,
26952695
return nullptr;
26962696
CallExpr *CE = cast<CallExpr>(Finder.getContexts().back().get<Expr*>());
26972697

2698+
if (CE->hasTrailingClosure())
2699+
// Call expression already has a trailing closure.
2700+
return nullptr;
2701+
26982702
// The last arugment is a closure?
26992703
Expr *Args = CE->getArg();
27002704
if (!Args)

test/refactoring/RefactoringKind/trailingclosure.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ func testTrailingClosure() -> String {
1212
[1,2,3]
1313
.filter({ $0 % 2 == 0 })
1414
.map({ $0 + 1 })
15+
16+
Foo.foo { 1 }
17+
Foo.bar { print(3); return 1 }
18+
Foo().qux(x: 1) { 1 }
1519
}
1620

1721
// RUN: %refactor -source-filename %s -pos=7:3 | %FileCheck %s -check-prefix=CHECK-TRAILING-CLOSURE
@@ -39,6 +43,10 @@ func testTrailingClosure() -> String {
3943
// RUN: %refactor -source-filename %s -pos=13:5 | %FileCheck %s -check-prefix=CHECK-TRAILING-CLOSURE
4044
// RUN: %refactor -source-filename %s -pos=14:5 | %FileCheck %s -check-prefix=CHECK-TRAILING-CLOSURE
4145

46+
// RUN: %refactor -source-filename %s -pos=16:7 | %FileCheck %s -check-prefix=CHECK-NO-TRAILING-CLOSURE
47+
// RUN: %refactor -source-filename %s -pos=17:7 | %FileCheck %s -check-prefix=CHECK-NO-TRAILING-CLOSURE
48+
// RUN: %refactor -source-filename %s -pos=18:9 | %FileCheck %s -check-prefix=CHECK-NO-TRAILING-CLOSURE
49+
4250
// CHECK-TRAILING-CLOSURE: Convert To Trailing Closure
4351

4452
// CHECK-NO-TRAILING-CLOSURE: Action begins

0 commit comments

Comments
 (0)