Skip to content

Commit d8c2290

Browse files
authored
Merge pull request github#9150 from tamasvajk/kotlin-MissingInstanceofInEquals
Kotlin: Add more type check casts to MissingInstanceofInEquals query
2 parents c518150 + 7d5844a commit d8c2290

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

java/ql/src/Likely Bugs/Comparison/MissingInstanceofInEquals.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class CheckedCast extends CastExpr {
2626
predicate hasTypeTest(Variable v) {
2727
any(InstanceOfExpr ioe).getExpr() = v.getAnAccess()
2828
or
29+
any(NotInstanceOfExpr nioe).getExpr() = v.getAnAccess()
30+
or
31+
any(SafeCastExpr sce).getExpr() = v.getAnAccess()
32+
or
2933
exists(MethodAccess ma |
3034
ma.getMethod().getName() = "getClass" and
3135
ma.getQualifier() = v.getAnAccess()

java/ql/test/kotlin/query-tests/MissingInstanceofInEquals/MissingInstanceofInEquals.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Likely Bugs/Comparison/MissingInstanceofInEquals.ql
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
data class D(val x: Int) {}
2+
3+
data class E(val x: Int) {
4+
override fun equals(other: Any?): Boolean {
5+
return (other as? E)?.x == this.x
6+
}
7+
}

0 commit comments

Comments
 (0)