Skip to content

Commit a715ebe

Browse files
committed
Swift: distinguish Pattern.get(Immediate)EnclosingPattern
1 parent 9353549 commit a715ebe

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

swift/ql/lib/codeql/swift/controlflow/internal/Completion.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private predicate switchMatching(SwitchStmt switch, CaseStmt c, AstNode ast) {
185185
(
186186
c.getALabel() = ast
187187
or
188-
ast.(Pattern).getEnclosingPattern+() = c.getALabel().getPattern()
188+
ast.(Pattern).getImmediateEnclosingPattern+() = c.getALabel().getPattern()
189189
)
190190
}
191191

@@ -216,7 +216,7 @@ predicate catchMatchingPattern(DoCatchStmt s, CaseStmt c, Pattern pattern) {
216216
exists(CaseLabelItem cli | catchMatching(s, c, cli) |
217217
cli.getPattern() = pattern
218218
or
219-
pattern.getEnclosingPattern+() = cli.getPattern()
219+
pattern.getImmediateEnclosingPattern+() = cli.getPattern()
220220
)
221221
}
222222

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
596596
exists(EnumElementPattern enumPat, NamedPattern namePat, int idx |
597597
enumPat.getMatchingExpr() = enumExpr and
598598
enumPat.getElement().getParam(idx) = enumParam and
599-
namePat.getIdentityPreservingEnclosingPattern*() = enumPat.getSubPattern(idx) and
599+
namePat.getImmediateIdentityPreservingEnclosingPattern*() = enumPat.getSubPattern(idx) and
600600
namePat.getVarDecl() = boundVar
601601
)
602602
)

swift/ql/lib/codeql/swift/elements/pattern/NamedPattern.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class NamedPattern extends Generated::NamedPattern {
1919
* This will be the case as long as the variable is subsequently used.
2020
*/
2121
VarDecl getVarDecl() {
22-
this.getEnclosingPattern*() = result.getParentPattern().getFullyUnresolved() and
22+
this.getImmediateEnclosingPattern*() = result.getParentPattern().getFullyUnresolved() and
2323
result.getName() = this.getName()
2424
}
2525

swift/ql/lib/codeql/swift/elements/pattern/Pattern.qll

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,28 @@ class Pattern extends Generated::Pattern {
7070
* Holds if this occurs as a sub-pattern of the result.
7171
*/
7272
Pattern getEnclosingPattern() {
73+
result = this.getFullyUnresolved().(Pattern).getImmediateEnclosingPattern()
74+
}
75+
76+
/**
77+
* Holds if this occurs as an immediate sub-pattern of the result.
78+
*/
79+
Pattern getImmediateEnclosingPattern() {
7380
this = result.(EnumElementPattern).getImmediateSubPattern()
7481
or
7582
this = result.(OptionalSomePattern).getImmediateSubPattern()
7683
or
7784
this = result.(TuplePattern).getImmediateElement(_)
7885
or
79-
result = this.getIdentityPreservingEnclosingPattern()
86+
result = this.getImmediateIdentityPreservingEnclosingPattern()
8087
}
8188

8289
/**
83-
* Holds if this occurs as a sub-pattern of the result
90+
* Holds if this occurs as an immediate sub-pattern of the result
8491
* without any intervening destructurings of
8592
* complex data structures.
8693
*/
87-
Pattern getIdentityPreservingEnclosingPattern() {
94+
Pattern getImmediateIdentityPreservingEnclosingPattern() {
8895
this = result.(BindingPattern).getImmediateSubPattern()
8996
or
9097
this = result.(IsPattern).getImmediateSubPattern()

0 commit comments

Comments
 (0)