Skip to content

Commit 99889b2

Browse files
committed
unified: Detect missing handling of ConditionalPattern
ConditionalPattern was not added to getEnclosingOrPattern() Update the test to detect the bug
1 parent 41bd516 commit 99889b2

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,5 +348,9 @@ func t38(value: E38) {
348348
case .a(let x), // $ access=x1 // name=x1
349349
.b(let x): // $ access=x1
350350
print(x) // $ access=x1
351+
352+
case .a(let y) where y < 1, // $ access=y1 // name=y1
353+
.b(let y): // $ access=y1
354+
print(y) // $ access=y1
351355
}
352356
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
testFailures
2+
ambiguousVariable
3+
| test.swift:352:10:353:17 | y | y | test.swift | 352 |
4+
| test.swift:352:17:352:17 | y | y | test.swift | 352 |

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ predicate keyValueCommentAt(string filepath, int line, string key, string value)
2323
module VariableAccessTest implements TestSig {
2424
string getARelevantTag() { result = "access" }
2525

26-
private predicate declAt(Variable v, string filepath, int line) {
27-
v.getLocation().hasLocationInfo(filepath, _, _, line, _)
26+
additional predicate declAt(Variable v, string filepath, int line) {
2827
v.getLocation().hasLocationInfo(filepath, line, _, _, _)
2928
}
3029

@@ -50,3 +49,13 @@ module VariableAccessTest implements TestSig {
5049
}
5150

5251
import MakeTest<VariableAccessTest>
52+
53+
private Variable getVariableAt(string name, string filepath, int line) {
54+
VariableAccessTest::declAt(result, filepath, line) and
55+
result.getName() = name
56+
}
57+
58+
query predicate ambiguousVariable(Variable v, string name, string filepath, int line) {
59+
v = getVariableAt(name, filepath, line) and
60+
strictcount(getVariableAt(name, filepath, line)) >= 2
61+
}

0 commit comments

Comments
 (0)