Skip to content

Commit 0953737

Browse files
authored
Merge pull request #37760 from hamishknight/walk-this-way
[ASTWalker] Walk ForEachStmt in source order
2 parents 397a9c6 + a6bb071 commit 0953737

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

lib/AST/ASTWalker.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,13 +1563,6 @@ Stmt *Traversal::visitForEachStmt(ForEachStmt *S) {
15631563
return nullptr;
15641564
}
15651565

1566-
if (Expr *Where = S->getWhere()) {
1567-
if ((Where = doIt(Where)))
1568-
S->setWhere(Where);
1569-
else
1570-
return nullptr;
1571-
}
1572-
15731566
// The iterator decl is built directly on top of the sequence
15741567
// expression, so don't visit both.
15751568
if (Expr *Sequence = S->getSequence()) {
@@ -1579,6 +1572,13 @@ Stmt *Traversal::visitForEachStmt(ForEachStmt *S) {
15791572
return nullptr;
15801573
}
15811574

1575+
if (Expr *Where = S->getWhere()) {
1576+
if ((Where = doIt(Where)))
1577+
S->setWhere(Where);
1578+
else
1579+
return nullptr;
1580+
}
1581+
15821582
if (auto IteratorNext = S->getConvertElementExpr()) {
15831583
if ((IteratorNext = doIt(IteratorNext)))
15841584
S->setConvertElementExpr(IteratorNext);

test/refactoring/ConvertAsync/basic.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,4 +855,22 @@ class TestConvertFunctionWithCallToFunctionsWithSpecialName {
855855
_ = x[1]
856856
return x
857857
}
858-
}
858+
}
859+
860+
// rdar://78781061
861+
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=FOR-IN-WHERE %s
862+
func testForInWhereRefactoring() {
863+
let arr: [String] = []
864+
for str in arr where str.count != 0 {
865+
simple { res in
866+
print(res)
867+
}
868+
}
869+
}
870+
// FOR-IN-WHERE: func testForInWhereRefactoring() async {
871+
// FOR-IN-WHERE-NEXT: let arr: [String] = []
872+
// FOR-IN-WHERE-NEXT: for str in arr where str.count != 0 {
873+
// FOR-IN-WHERE-NEXT: let res = await simple()
874+
// FOR-IN-WHERE-NEXT: print(res)
875+
// FOR-IN-WHERE-NEXT: }
876+
// FOR-IN-WHERE-NEXT: }

0 commit comments

Comments
 (0)