Skip to content

Commit 69adfac

Browse files
committed
[Scope map] Deal with some previously-broken ASTs
1 parent c612f4f commit 69adfac

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/AST/ASTScope.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ void ASTScope::expand() const {
222222
patternBinding.decl->getPatternList()[patternBinding.entry];
223223

224224
// Create a child for the initializer, if present.
225-
if (patternEntry.getInit())
225+
if (patternEntry.getInit() &&
226+
patternEntry.getInit()->getSourceRange().isValid())
226227
addChild(new (ctx) ASTScope(ASTScopeKind::PatternInitializer, this,
227228
patternBinding.decl, patternBinding.entry));
228229

@@ -933,6 +934,7 @@ ASTScope *ASTScope::createIfNeeded(const ASTScope *parent, Stmt *stmt) {
933934
ASTContext &ctx = parent->getASTContext();
934935
switch (stmt->getKind()) {
935936
case StmtKind::Brace:
937+
if (stmt->getSourceRange().isInvalid()) return nullptr;
936938
return new (ctx) ASTScope(parent, cast<BraceStmt>(stmt));
937939

938940
case StmtKind::Return: {

test/NameBinding/scope_map.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ struct PatternInitializers {
179179
(c, d) = (1.5, 2.5)
180180
}
181181

182+
protocol ProtoWithSubscript {
183+
subscript(native: Int) -> Int { get set }
184+
}
185+
186+
func localPatternsWithSharedType() {
187+
let i, j, k: Int
188+
}
189+
182190
// RUN: not %target-swift-frontend -dump-scope-maps expanded %s 2> %t.expanded
183191
// RUN: %FileCheck -check-prefix CHECK-EXPANDED %s < %t.expanded
184192

@@ -370,6 +378,24 @@ struct PatternInitializers {
370378
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [167:32 - 167:42] expanded
371379
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} defaultArguments(i:j:) param 0:1 [167:48 - 175:1] expanded
372380

381+
// CHECK-EXPANDED: -Accessors {{.*}} scope_map.(file).ProtoWithSubscript.subscript@{{.*}}scope_map.swift:183:3 [183:33 - 183:43] expanded
382+
// CHECK-EXPANDED-NEXT: |-AbstractFunctionDecl {{.*}} _ [183:35 - 183:35] expanded
383+
// CHECK-EXPANDED-NEXT: `-AbstractFunctionParams {{.*}} _ param 0:0 [183:35 - 183:35] expanded
384+
// CHECK-EXPANDED-NEXT: `-AbstractFunctionParams {{.*}} _ param 1:0 [183:35 - 183:35] expanded
385+
// CHECK-EXPANDED-NEXT: `-AbstractFunctionDecl {{.*}} _ [183:39 - 183:39] expanded
386+
// CHECK-EXPANDED-NEXT: `-AbstractFunctionParams {{.*}} _ param 0:0 [183:39 - 183:39] expanded
387+
// CHECK-EXPANDED-NEXT: `-AbstractFunctionParams {{.*}} _ param 1:0 [183:39 - 183:39] expanded
388+
// CHECK-EXPANDED-NEXT: `-AbstractFunctionParams {{.*}} _ param 1:1 [183:39 - 183:39] expanded
389+
390+
// CHECK-EXPANDED: `-AbstractFunctionDecl {{.*}} localPatternsWithSharedType() [186:1 - 188:1] expanded
391+
// CHECK-EXPANDED-NEXT: `-BraceStmt {{.*}} [186:36 - 188:1] expanded
392+
// CHECK-EXPANDED-NEXT: `-PatternBinding {{.*}} entry 0 [187:7 - 188:1] expanded
393+
// CHECK-EXPANDED-NEXT: `-AfterPatternBinding {{.*}} entry 0 [187:7 - 188:1] expanded
394+
// CHECK-EXPANDED-NEXT: `-PatternBinding {{.*}} entry 1 [187:10 - 188:1] expanded
395+
// CHECK-EXPANDED-NEXT: `-AfterPatternBinding {{.*}} entry 1 [187:10 - 188:1] expanded
396+
// CHECK-EXPANDED-NEXT: `-PatternBinding {{.*}} entry 2 [187:13 - 188:1] expanded
397+
// CHECK-EXPANDED-NEXT: `-AfterPatternBinding {{.*}} entry 2 [187:16 - 188:1] expanded
398+
373399
// RUN: not %target-swift-frontend -dump-scope-maps 70:8,26:20,5:18,166:32,179:18 %s 2> %t.searches
374400
// RUN: %FileCheck -check-prefix CHECK-SEARCHES %s < %t.searches
375401

0 commit comments

Comments
 (0)