Skip to content

Commit 5ba941e

Browse files
committed
unified: Handle ConditionalPattern in local scoping
1 parent 3923eff commit 5ba941e

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

unified/ql/lib/codeql/unified/internal/Variables.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig<Locatio
178178
)
179179
or
180180
exists(CatchClause catch |
181-
scope = catch and // ensure both 'body' and 'guard' clause are in scope
181+
scope = catch and // ensure both body and pattern are in scope
182182
pattern = catch.getPattern()
183183
)
184184
or
185185
exists(SwitchCase case |
186-
scope = case and // ensure both 'body' and 'guard' clause are in scope (TODO: merge CatchClause and SwitchCase?)
186+
scope = case and // ensure both body and pattern are in scope
187187
pattern = case.getPattern()
188188
)
189189
or
@@ -207,6 +207,11 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig<Locatio
207207
pattern = pat.getPattern(_)
208208
)
209209
or
210+
exists(ConditionalPattern pat |
211+
bindingContext(pat, scope) and
212+
pattern = pat.getPattern()
213+
)
214+
or
210215
exists(PatternGuardExpr expr |
211216
pattern = expr.getPattern() and
212217
scope = expr

unified/ql/test/library-tests/variables/test.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func t10(value: Int) { // name=value1
8080
// Switch with multiple cases
8181
func t11(value: Int) { // name=value1
8282
switch value { // $ access=value1
83-
case let x where x > 0: // $ MISSING: access=x1 // name=x1
84-
print(x) // $ MISSING: access=x1
83+
case let x where x > 0: // $ access=x1 // name=x1
84+
print(x) // $ access=x1
8585
case let x: // name=x2
8686
print(x) // $ access=x2
8787
}

0 commit comments

Comments
 (0)