Skip to content

Commit 9db82cb

Browse files
committed
[AST] Avoid walking a few more expressions in WalkToVarDecls
Avoid walking TapExprs, SingleValueStmtExprs, and key paths. The latter is important since they can contain invalid VarDecls that will no longer be visited by the ASTWalker after key path resolution, so we don't want to create case body vars for them.
1 parent b72ef8e commit 9db82cb

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

lib/AST/Pattern.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,14 @@ namespace {
208208
return Action::Continue(P);
209209
}
210210

211-
// Only walk into an expression insofar as it doesn't open a new scope -
212-
// that is, don't walk into a closure body.
213211
PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
214-
if (isa<ClosureExpr>(E)) {
212+
// Only walk into an expression insofar as it doesn't open a new scope -
213+
// that is, don't walk into a closure body, TapExpr, or
214+
// SingleValueStmtExpr. Also don't walk into key paths since any nested
215+
// VarDecls are invalid there, and after being diagnosed by key path
216+
// resolution the ASTWalker won't visit them.
217+
if (isa<ClosureExpr>(E) || isa<TapExpr>(E) ||
218+
isa<SingleValueStmtExpr>(E) || isa<KeyPathExpr>(E)) {
215219
return Action::SkipNode(E);
216220
}
217221
return Action::Continue(E);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// {"kind":"complete","original":"19b878fc","signature":"swift::NamingPatternRequest::evaluate(swift::Evaluator&, swift::VarDecl*) const","signatureAssert":"Assertion failed: (foundVarDecl && \"VarDecl not declared in its parent?\"), function evaluate"}
2+
// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
3+
{
4+
guard let \a = answer
5+
a
6+
#^^#

validation-test/compiler_crashers_2/22119c306663e633.swift renamed to validation-test/compiler_crashers_2_fixed/22119c306663e633.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"signature":"swift::NamingPatternRequest::evaluate(swift::Evaluator&, swift::VarDecl*) const"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
{
44
let a = $0.c ;
55
switch a {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"kind":"typecheck","signature":"swift::NamingPatternRequest::evaluate(swift::Evaluator&, swift::VarDecl*) const","signatureAssert":"Assertion failed: (foundVarDecl && \"VarDecl not declared in its parent?\"), function evaluate"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
{
44
if
55
case.(let \ a) { a

validation-test/compiler_crashers_2/9ae5dcaffa1a80.swift renamed to validation-test/compiler_crashers_2_fixed/9ae5dcaffa1a80.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"signature":"void (anonymous namespace)::StmtChecker::checkSiblingCaseStmts<swift::CaseStmt* const*>(swift::CaseStmt* const*, swift::CaseStmt* const*, swift::CaseParentKind, bool&, swift::Type)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
enum a func b(c : a) -> Int {
44
switch
55
c {

0 commit comments

Comments
 (0)