Skip to content

Commit 7b00d52

Browse files
authored
Merge pull request #34571 from slavapestov/fix-astscope-assert
ASTScope: Fix assertion with pattern bindings that don't introduce any variables
2 parents 6b6e419 + 6599bef commit 7b00d52

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/AST/ASTScopeCreation.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,13 +544,16 @@ ScopeCreator::addPatternBindingToScopeTree(PatternBindingDecl *patternBinding,
544544
if (auto *var = patternBinding->getSingleVar())
545545
addChildrenForKnownAttributes(var, parentScope);
546546

547-
auto *insertionPoint = parentScope;
547+
bool isLocalBinding = false;
548548
for (auto i : range(patternBinding->getNumPatternEntries())) {
549-
bool isLocalBinding = false;
550549
if (auto *varDecl = patternBinding->getAnchoringVarDecl(i)) {
551550
isLocalBinding = varDecl->getDeclContext()->isLocalContext();
551+
break;
552552
}
553+
}
553554

555+
auto *insertionPoint = parentScope;
556+
for (auto i : range(patternBinding->getNumPatternEntries())) {
554557
Optional<SourceLoc> endLocForBinding = None;
555558
if (isLocalBinding) {
556559
endLocForBinding = endLoc;

test/decl/var/variables.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,8 @@ if true {
131131
_ = s
132132
}
133133

134-
134+
// ASTScope assertion
135+
func patternBindingWithTwoEntries() {
136+
let x2 = 1, (_, _) = (1, 2)
137+
// expected-warning@-1 {{immutable value 'x2' was never used; consider replacing with '_' or removing it}}
138+
}

0 commit comments

Comments
 (0)