Skip to content

Commit 40e20a2

Browse files
committed
Don't apply "Convert to Trailing Closure" to call with multiple trailing closures
Previously we'd perform an invalid transform or hit an assertion failure. For now, disallow the transform for a call that already uses trailing closure syntax. rdar://81106400
1 parent 41a1761 commit 40e20a2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3709,7 +3709,7 @@ static CallExpr *findTrailingClosureTarget(
37093709
return nullptr;
37103710
CallExpr *CE = cast<CallExpr>(contexts.back().get<Expr*>());
37113711

3712-
if (CE->hasTrailingClosure())
3712+
if (CE->getUnlabeledTrailingClosureIndex().hasValue())
37133713
// Call expression already has a trailing closure.
37143714
return nullptr;
37153715

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
func lottaClosures(x: () -> Void, y: () -> Void, z: () -> Void) {
2+
lottaClosures(x: {}) {} z: {}
3+
}
4+
// RUN: not %refactor -trailingclosure -source-filename %s -pos=2:3
5+
6+
func singleClosure(x: () -> Void) {
7+
singleClosure {}
8+
}
9+
// RUN: not %refactor -trailingclosure -source-filename %s -pos=7:3

0 commit comments

Comments
 (0)