Skip to content

Commit 74ecacc

Browse files
committed
[ASTWalker] Fix ArgumentList walking bug
We were accidentally continuing to walk the old argument list even if the caller had returned a new one.
1 parent 488e91a commit 74ecacc

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

lib/AST/ASTWalker.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,16 +1342,17 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
13421342
}
13431343

13441344
ArgumentList *doIt(ArgumentList *ArgList) {
1345-
auto Pre = Walker.walkToArgumentListPre(ArgList);
1346-
if (!Pre.first || !Pre.second)
1347-
return Pre.second;
1345+
bool WalkChildren;
1346+
std::tie(WalkChildren, ArgList) = Walker.walkToArgumentListPre(ArgList);
1347+
if (!WalkChildren || !ArgList)
1348+
return ArgList;
13481349

1349-
for (auto Idx : indices(*Pre.second)) {
1350+
for (auto Idx : indices(*ArgList)) {
13501351
auto *E = doIt(ArgList->getExpr(Idx));
13511352
if (!E) return nullptr;
13521353
ArgList->setExpr(Idx, E);
13531354
}
1354-
return Walker.walkToArgumentListPost(Pre.second);
1355+
return Walker.walkToArgumentListPost(ArgList);
13551356
}
13561357
};
13571358

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CC | %FileCheck %s
2+
3+
@resultBuilder
4+
struct Builder {
5+
static func buildBlock<T>(_ components: T...) -> T {
6+
fatalError()
7+
}
8+
}
9+
10+
enum E {
11+
case e
12+
}
13+
14+
struct S {
15+
init(_ x: String) {}
16+
func foo(_ x: String? = nil, y: E) -> S {
17+
fatalError()
18+
}
19+
}
20+
21+
struct R {
22+
@Builder
23+
var foo: S {
24+
// The argument list for foo gets rewritten to remove the DefaultArgumentExpr
25+
// when doing a fallback type-check. Make sure we can continue to correctly
26+
// recover the MemberRefExpr from DeclRefExpr for .e
27+
S(E.#^CC^#).foo(y: .e)
28+
// CHECK: Begin completions
29+
// CHECK: Decl[EnumElement]/CurrNominal: e[#E#]; name=e
30+
// CHECK: End completions
31+
}
32+
}
33+

0 commit comments

Comments
 (0)