Add tests for "implicit this"

This commit is contained in:
Taus
2021-10-13 12:27:20 +00:00
committed by GitHub
parent 48cfa9665a
commit bc5e0924d2
5 changed files with 42 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
import ql
class Foo extends string {
Foo() { this = "hello" }
string getBar() { result = "bar" }
string getBarWithThis() { result = this.getBar() }
string getBarWithoutThis() { result = getBar() }
}

View File

@@ -0,0 +1,16 @@
import ql
class Foo extends string {
Foo() { this = "hello" }
string getBar() { result = "bar" }
string getBarWithThis() { result = this.getBar() }
/* Okay because not a member predicate. */
string getBaz() { result = Baz::baz() }
}
module Baz {
string baz() { result = "baz" }
}

View File

@@ -0,0 +1 @@
| Bad.qll:10:41:10:48 | PredicateCall | Use of implicit `this`. |

View File

@@ -0,0 +1 @@
queries/style/ImplicitThis.ql

View File

@@ -0,0 +1,13 @@
import ql
class Foo extends string {
Foo() { this = "hello" }
string getBar() { result = "bar" }
/* Okay, because we don't write `this.some_method` anywhere */
string getBarWithoutThis() { result = getBar() }
/* Okay, because this is the only way to cast `this`. */
string useThisWithInlineCast() { result = this.(string).toUpperCase() }
}