Skip to content

Commit 6a12726

Browse files
committed
Swift: distinguish between Pattern.get(Immediate)IdentityPreservingEnclosingPattern
1 parent 7dc7938 commit 6a12726

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,27 @@ class Pattern extends Generated::Pattern {
6464
}
6565

6666
/** Holds if this pattern is matched against an expression. */
67-
predicate hasMatchingExpr() { exists(this.getMatchingExpr()) }
67+
final predicate hasMatchingExpr() { exists(this.getMatchingExpr()) }
6868

6969
/**
70-
* Holds if this occurs as a sub-pattern of the result.
70+
* Gets the parent pattern of this pattern, if any.
7171
*/
72-
Pattern getEnclosingPattern() {
72+
final Pattern getEnclosingPattern() {
7373
result = this.getFullyUnresolved().(Pattern).getImmediateEnclosingPattern()
7474
}
7575

7676
/**
77-
* Holds if this occurs as an immediate sub-pattern of the result.
77+
* Gets the parent pattern of this pattern, but only if
78+
* both patterns match against the same object, which is not
79+
* the case when destructuring a complex data structure,
80+
* like a tuple or enum.
81+
*/
82+
final Pattern getIdentityPreservingEnclosingPattern() {
83+
result = this.getFullyUnresolved().(Pattern).getImmediateIdentityPreservingEnclosingPattern()
84+
}
85+
86+
/**
87+
* Gets the parent pattern of this pattern, if any.
7888
*/
7989
Pattern getImmediateEnclosingPattern() {
8090
this = result.(EnumElementPattern).getImmediateSubPattern()
@@ -87,9 +97,10 @@ class Pattern extends Generated::Pattern {
8797
}
8898

8999
/**
90-
* Holds if this occurs as an immediate sub-pattern of the result
91-
* without any intervening destructurings of
92-
* complex data structures.
100+
* Gets the immediate parent pattern of this pattern, but only if
101+
* both patterns match against the same object, which is not
102+
* the case when destructuring a complex data structure,
103+
* like a tuple or enum.
93104
*/
94105
Pattern getImmediateIdentityPreservingEnclosingPattern() {
95106
this = result.(BindingPattern).getImmediateSubPattern()

0 commit comments

Comments
 (0)