Skip to content

Commit a0e2bd5

Browse files
authored
QL: Add tests for "implicit this"
1 parent fb5513c commit a0e2bd5

5 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ql
2+
3+
class Foo extends string {
4+
Foo() { this = "hello" }
5+
6+
string getBar() { result = "bar" }
7+
8+
string getBarWithThis() { result = this.getBar() }
9+
10+
string getBarWithoutThis() { result = getBar() }
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import ql
2+
3+
class Foo extends string {
4+
Foo() { this = "hello" }
5+
6+
string getBar() { result = "bar" }
7+
8+
string getBarWithThis() { result = this.getBar() }
9+
10+
/* Okay because not a member predicate. */
11+
string getBaz() { result = Baz::baz() }
12+
}
13+
14+
module Baz {
15+
string baz() { result = "baz" }
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| Bad.qll:10:41:10:48 | PredicateCall | Use of implicit `this`. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/style/ImplicitThis.ql
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import ql
2+
3+
class Foo extends string {
4+
Foo() { this = "hello" }
5+
6+
string getBar() { result = "bar" }
7+
8+
/* Okay, because we don't write `this.some_method` anywhere */
9+
string getBarWithoutThis() { result = getBar() }
10+
11+
/* Okay, because this is the only way to cast `this`. */
12+
string useThisWithInlineCast() { result = this.(string).toUpperCase() }
13+
}

0 commit comments

Comments
 (0)