Skip to content

Commit c2b9ffc

Browse files
authored
Merge pull request #17291 from rintaro/refactoring-trailingclosure-tupleshuffle
[Refactoring] Handle TupleShuffleExpr in "convert to trailing closure" action
2 parents 359385b + 1ca8847 commit c2b9ffc

File tree

9 files changed

+57
-2
lines changed

9 files changed

+57
-2
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2775,7 +2775,7 @@ bool RefactoringActionTrailingClosure::performChange() {
27752775
return true;
27762776
Expr *Args = CE->getArg();
27772777
if (auto *TSE = dyn_cast<TupleShuffleExpr>(Args))
2778-
Args = TSE;
2778+
Args = TSE->getSubExpr();
27792779

27802780
Expr *ClosureArg = nullptr;
27812781
Expr *PrevArg = nullptr;

test/refactoring/TrailingClosure/Outputs/basic/L10.swift.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ func testTrailingClosure() -> String {
1414
.map({ $0 + 1 })
1515
}
1616

17+
func foobar(first: String? = nil, closure: () -> Void) { fatalError() }
18+
func blah() {
19+
_ = foobar(closure: { print("foo") })
20+
}
1721

1822

1923

test/refactoring/TrailingClosure/Outputs/basic/L13.swift.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ func testTrailingClosure() -> String {
1414
.map({ $0 + 1 })
1515
}
1616

17+
func foobar(first: String? = nil, closure: () -> Void) { fatalError() }
18+
func blah() {
19+
_ = foobar(closure: { print("foo") })
20+
}
1721

1822

1923

test/refactoring/TrailingClosure/Outputs/basic/L14.swift.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ func testTrailingClosure() -> String {
1414
.map { $0 + 1 }
1515
}
1616

17+
func foobar(first: String? = nil, closure: () -> Void) { fatalError() }
18+
func blah() {
19+
_ = foobar(closure: { print("foo") })
20+
}
1721

1822

1923

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
struct Foo {
2+
static func foo(a: () -> Int) {}
3+
func qux(x: Int, y: () -> Int ) {}
4+
}
5+
6+
func testTrailingClosure() -> String {
7+
Foo.foo(a: { 1 })
8+
Foo.bar(a: { print(3); return 1 })
9+
Foo().qux(x: 1, y: { 1 })
10+
let _ = Foo().quux(x: 1, y: { 1 })
11+
12+
[1,2,3]
13+
.filter({ $0 % 2 == 0 })
14+
.map({ $0 + 1 })
15+
}
16+
17+
func foobar(first: String? = nil, closure: () -> Void) { fatalError() }
18+
func blah() {
19+
_ = foobar { print("foo") }
20+
}
21+
22+
23+
24+
25+

test/refactoring/TrailingClosure/Outputs/basic/L7.swift.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ func testTrailingClosure() -> String {
1414
.map({ $0 + 1 })
1515
}
1616

17+
func foobar(first: String? = nil, closure: () -> Void) { fatalError() }
18+
func blah() {
19+
_ = foobar(closure: { print("foo") })
20+
}
1721

1822

1923

test/refactoring/TrailingClosure/Outputs/basic/L8.swift.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ func testTrailingClosure() -> String {
1414
.map({ $0 + 1 })
1515
}
1616

17+
func foobar(first: String? = nil, closure: () -> Void) { fatalError() }
18+
func blah() {
19+
_ = foobar(closure: { print("foo") })
20+
}
1721

1822

1923

test/refactoring/TrailingClosure/Outputs/basic/L9.swift.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ func testTrailingClosure() -> String {
1414
.map({ $0 + 1 })
1515
}
1616

17+
func foobar(first: String? = nil, closure: () -> Void) { fatalError() }
18+
func blah() {
19+
_ = foobar(closure: { print("foo") })
20+
}
1721

1822

1923

test/refactoring/TrailingClosure/basic.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ func testTrailingClosure() -> String {
1313
.filter({ $0 % 2 == 0 })
1414
.map({ $0 + 1 })
1515
}
16+
17+
func foobar(first: String? = nil, closure: () -> Void) { fatalError() }
18+
func blah() {
19+
_ = foobar(closure: { print("foo") })
20+
}
1621
// RUN: %empty-directory(%t.result)
1722

1823
// RUN: %refactor -trailingclosure -source-filename %s -pos=7:3 > %t.result/L7.swift
@@ -31,4 +36,5 @@ func testTrailingClosure() -> String {
3136
// RUN: diff -u %S/Outputs/basic/L13.swift.expected %t.result/L13.swift
3237
// RUN: %refactor -trailingclosure -source-filename %s -pos=14:5 > %t.result/L14.swift
3338
// RUN: diff -u %S/Outputs/basic/L14.swift.expected %t.result/L14.swift
34-
39+
// RUN: %refactor -trailingclosure -source-filename %s -pos=19:7 > %t.result/L19.swift
40+
// RUN: diff -u %S/Outputs/basic/L19.swift.expected %t.result/L19.swift

0 commit comments

Comments
 (0)