mirror of
https://github.com/github/codeql.git
synced 2026-05-01 11:45:14 +02:00
Kotlin: Add support for implicit casts
This commit is contained in:
@@ -1497,6 +1497,16 @@ class X {
|
||||
extractTypeAccess(e.typeOperand, id, 0, e)
|
||||
extractExpressionExpr(e.argument, callable, id, 1)
|
||||
}
|
||||
IrTypeOperator.IMPLICIT_CAST -> {
|
||||
// TODO: Make this distinguishable from an explicit cast?
|
||||
val id = tw.getFreshIdLabel<DbCastexpr>()
|
||||
val locId = tw.getLocation(e)
|
||||
val type = useType(e.type)
|
||||
tw.writeExprs_castexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
|
||||
tw.writeHasLocation(id, locId)
|
||||
extractTypeAccess(e.typeOperand, id, 0, e)
|
||||
extractExpressionExpr(e.argument, callable, id, 1)
|
||||
}
|
||||
IrTypeOperator.INSTANCEOF -> {
|
||||
val id = tw.getFreshIdLabel<DbInstanceofexpr>()
|
||||
val locId = tw.getLocation(e)
|
||||
|
||||
@@ -81,3 +81,11 @@
|
||||
| exprs.kt:53:9:53:18 | n | VarAccess |
|
||||
| exprs.kt:54:27:54:31 | new C(...) | ClassInstanceExpr |
|
||||
| exprs.kt:54:29:54:30 | 42 | IntegerLiteral |
|
||||
| exprs.kt:57:1:57:18 | <obinit>(...) | MethodAccess |
|
||||
| exprs.kt:58:1:58:26 | <obinit>(...) | MethodAccess |
|
||||
| exprs.kt:59:1:59:26 | <obinit>(...) | MethodAccess |
|
||||
| exprs.kt:62:5:64:5 | when ... | WhenExpr |
|
||||
| exprs.kt:62:8:62:8 | x | VarAccess |
|
||||
| exprs.kt:62:8:62:21 | ...instanceof... | InstanceOfExpr |
|
||||
| exprs.kt:62:8:62:21 | Subclass1 | TypeAccess |
|
||||
| exprs.kt:63:9:63:28 | y | LocalVariableDeclExpr |
|
||||
|
||||
@@ -53,3 +53,13 @@ fun getClass() {
|
||||
class C(val n: Int) {
|
||||
fun foo(): C { return C(42) }
|
||||
}
|
||||
|
||||
open class Root {}
|
||||
class Subclass1: Root() {}
|
||||
class Subclass2: Root() {}
|
||||
|
||||
fun typeTests(x: Root) {
|
||||
if(x is Subclass1) {
|
||||
val y: Subclass1 = x
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user