Remove ql/implicit-this restriction to files with explicit this

This commit is contained in:
Kasper Svendsen
2023-05-11 12:41:02 +02:00
parent 082e6a1245
commit a920c13869
4 changed files with 11 additions and 14 deletions

View File

@@ -1,12 +1,5 @@
import ql
MemberCall explicitThisCallInFile(File f) {
result.getLocation().getFile() = f and
result.getBase() instanceof ThisAccess and
// Exclude `this.(Type).whatever(...)`, as some files have that as their only instance of `this`.
not result = any(InlineCast c).getBase()
}
PredicateCall implicitThisCallInFile(File f) {
result.getLocation().getFile() = f and
exists(result.getTarget().getDeclaringType().getASuperType()) and
@@ -14,7 +7,4 @@ PredicateCall implicitThisCallInFile(File f) {
not exists(result.getQualifier())
}
PredicateCall confusingImplicitThisCall(File f) {
result = implicitThisCallInFile(f) and
exists(explicitThisCallInFile(f))
}
PredicateCall confusingImplicitThisCall(File f) { result = implicitThisCallInFile(f) }

View File

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

View File

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

View File

@@ -5,9 +5,6 @@ class Foo extends string {
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() }
}