Skip to content

Commit f501003

Browse files
committed
Design Patterns: Recommend this = range for ::Range pattern
1 parent e859a80 commit f501003

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

docs/ql-design-patterns.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ use
3232
* extend `MySpecialExpr::Range` instead.
3333
*/
3434
class MySpecialExpr extends Expr {
35-
MySpecialExpr::Range self;
35+
MySpecialExpr::Range range;
3636
37-
MySpecialExpr() { this = self }
37+
MySpecialExpr() { this = range }
3838
3939
/** <QLDoc...> */
40-
int memberPredicate() { result = self.memberPredicate() }
40+
int memberPredicate() { result = range.memberPredicate() }
4141
}
4242
4343
/** Provides a class for modeling new <...> APIs. */
@@ -61,6 +61,8 @@ class ConcreteSubclass extends MySpecialExpr::Range { ... }
6161

6262
</details>
6363

64+
Note, previously we used to write `MySpecialExpr() { this = self }`, but we now recommend using `MySpecialExpr() { this = range }` instead to avoid anyone mistakenly thinking that `self` and `this` are synonyms in general.
65+
6466
### Rationale
6567

6668
Let's use an example from the Go libraries: https://github.com/github/codeql-go/blob/2ba9bbfd8ba1818b5ee9f6009c86a605189c9ef3/ql/src/semmle/go/Concepts.qll#L119-L157

0 commit comments

Comments
 (0)