Merge pull request #9150 from tamasvajk/kotlin-MissingInstanceofInEquals

Kotlin: Add more type check casts to MissingInstanceofInEquals query
This commit is contained in:
Tamás Vajk
2022-05-17 08:43:06 +02:00
committed by GitHub
4 changed files with 12 additions and 0 deletions

View File

@@ -26,6 +26,10 @@ class CheckedCast extends CastExpr {
predicate hasTypeTest(Variable v) {
any(InstanceOfExpr ioe).getExpr() = v.getAnAccess()
or
any(NotInstanceOfExpr nioe).getExpr() = v.getAnAccess()
or
any(SafeCastExpr sce).getExpr() = v.getAnAccess()
or
exists(MethodAccess ma |
ma.getMethod().getName() = "getClass" and
ma.getQualifier() = v.getAnAccess()

View File

@@ -0,0 +1 @@
Likely Bugs/Comparison/MissingInstanceofInEquals.ql

View File

@@ -0,0 +1,7 @@
data class D(val x: Int) {}
data class E(val x: Int) {
override fun equals(other: Any?): Boolean {
return (other as? E)?.x == this.x
}
}