mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Kotlin: Improve java/abstract-to-concrete-cast to handle when branches
This commit is contained in:
@@ -16,8 +16,11 @@ import java
|
||||
import semmle.code.java.Collections
|
||||
|
||||
predicate guardedByInstanceOf(VarAccess e, RefType t) {
|
||||
exists(IfStmt s, InstanceOfExpr instanceCheck, RefType checkType |
|
||||
s.getCondition() = instanceCheck and
|
||||
exists(Stmt s, InstanceOfExpr instanceCheck, RefType checkType |
|
||||
(
|
||||
s.(IfStmt).getCondition() = instanceCheck or
|
||||
s.(WhenBranch).getCondition() = instanceCheck
|
||||
) and
|
||||
instanceCheck.getCheckedType() = checkType and
|
||||
// The same variable appears as the subject of the `instanceof`.
|
||||
instanceCheck.getExpr() = e.getVariable().getAnAccess() and
|
||||
@@ -27,7 +30,11 @@ predicate guardedByInstanceOf(VarAccess e, RefType t) {
|
||||
(checkType = t or checkType = t.getSourceDeclaration().(GenericType).getRawType()) and
|
||||
// The expression appears in one of the branches.
|
||||
// (We do not verify here whether the guard is correctly implemented.)
|
||||
exists(Stmt branch | branch = s.getThen() or branch = s.getElse() |
|
||||
exists(Stmt branch |
|
||||
branch = s.(IfStmt).getThen() or
|
||||
branch = s.(IfStmt).getElse() or
|
||||
branch = s.(WhenBranch).getRhs()
|
||||
|
|
||||
branch = e.getEnclosingStmt().getEnclosingStmt+()
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
| Test.kt:3:9:3:9 | <implicit cast> | $@ is cast to the concrete type $@, losing abstraction. | file:///modules/java.base/java/util/List.class:0:0:0:0 | List | List<Integer> | file:///modules/java.base/java/util/ArrayList.class:0:0:0:0 | ArrayList | ArrayList<Integer> |
|
||||
|
||||
Reference in New Issue
Block a user