Skip to content

Commit 1a808ab

Browse files
committed
[IDE] Fix SyntaxModel to corretly walk sequence expression correctly
* Handle sequence expression at call argument position * Set the sequence expression as the parent when walking into its sub expressions. * Correctly call walkToExprPost() to the sequence expression. rdar://problem/47603866 / https://bugs.swift.org/browse/SR-9776 (cherry picked from commit e7700dc)
1 parent 0d2be92 commit 1a808ab

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

lib/IDE/SyntaxModel.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -425,18 +425,6 @@ std::pair<bool, Expr *> ModelASTWalker::walkToExprPre(Expr *E) {
425425
if (isVisitedBeforeInIfConfig(E))
426426
return {false, E};
427427

428-
// In SequenceExpr, explicit cast expressions (e.g. 'as', 'is') appear twice.
429-
// Skip pointers we've already seen.
430-
if (auto SE = dyn_cast<SequenceExpr>(E)) {
431-
SmallPtrSet<Expr *, 5> seenExpr;
432-
for (auto subExpr : SE->getElements()) {
433-
if (!seenExpr.insert(subExpr).second)
434-
continue;
435-
subExpr->walk(*this);
436-
}
437-
return { false, SE };
438-
}
439-
440428
auto addCallArgExpr = [&](Expr *Elem, TupleExpr *ParentTupleExpr) {
441429
if (isCurrentCallArgExpr(ParentTupleExpr)) {
442430
CharSourceRange NR = parameterNameRangeOfCallArg(ParentTupleExpr, Elem);
@@ -558,6 +546,18 @@ std::pair<bool, Expr *> ModelASTWalker::walkToExprPre(Expr *E) {
558546
Closure->getExplicitResultTypeLoc().getSourceRange());
559547

560548
pushStructureNode(SN, Closure);
549+
} else if (auto SE = dyn_cast<SequenceExpr>(E)) {
550+
// In SequenceExpr, explicit cast expressions (e.g. 'as', 'is') appear
551+
// twice. Skip pointers we've already seen.
552+
SmallPtrSet<Expr *, 5> seenExpr;
553+
for (auto subExpr : SE->getElements()) {
554+
if (!seenExpr.insert(subExpr).second) {
555+
continue;
556+
}
557+
llvm::SaveAndRestore<ASTWalker::ParentTy> SetParent(Parent, E);
558+
subExpr->walk(*this);
559+
}
560+
return { false, walkToExprPost(SE) };
561561
}
562562

563563
return { true, E };

test/IDE/structure.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,8 @@ completion(a: 1) { (x: Any, y: Int) -> Int in
282282
// CHECK: <call><name>completion</name>(<arg><name>a</name>: 1</arg>) <arg><closure>{ (<param>x: <type>Any</type></param>, <param>y: <type>Int</type></param>) -> <type>Int</type> in
283283
// CHECK: return x as! Int + y
284284
// CHECK: }</closure></arg></call>
285+
286+
myFunc(foo: 0,
287+
bar: baz == 0)
288+
// CHECK: <call><name>myFunc</name>(<arg><name>foo</name>: 0</arg>,
289+
// CHECK: <arg><name>bar</name>: baz == 0</arg>)</call>

0 commit comments

Comments
 (0)