mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Merge pull request #10255 from tamasvajk/kotlin-array-get-fix
Kotlin: Fix array indexer extraction
This commit is contained in:
@@ -2185,7 +2185,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
}
|
||||
}
|
||||
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "get") && c.origin == IrStatementOrigin.GET_ARRAY_ELEMENT -> {
|
||||
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "get") && c.origin == IrStatementOrigin.GET_ARRAY_ELEMENT && c.dispatchReceiver != null -> {
|
||||
val id = tw.getFreshIdLabel<DbArrayaccess>()
|
||||
val type = useType(c.type)
|
||||
tw.writeExprs_arrayaccess(id, type.javaResult.id, parent, idx)
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
test.kt:
|
||||
# 0| [CompilationUnit] test
|
||||
# 0| 1: [Class] TestKt
|
||||
# 1| 1: [Method] fn
|
||||
# 1| 3: [TypeAccess] Unit
|
||||
#-----| 4: (Parameters)
|
||||
# 1| 0: [Parameter] arr
|
||||
# 1| 0: [TypeAccess] byte[]
|
||||
# 1| 1: [Parameter] mt
|
||||
# 1| 0: [TypeAccess] C
|
||||
# 1| 5: [BlockStmt] { ... }
|
||||
# 2| 0: [ExprStmt] <Expr>;
|
||||
# 2| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
|
||||
# 2| 0: [TypeAccess] Unit
|
||||
# 2| 1: [ArrayAccess] ...[...]
|
||||
# 2| 0: [VarAccess] arr
|
||||
# 2| 1: [IntegerLiteral] 1
|
||||
# 3| 1: [ExprStmt] <Expr>;
|
||||
# 3| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
|
||||
# 3| 0: [TypeAccess] Unit
|
||||
# 3| 1: [MethodAccess] get(...)
|
||||
# 3| -1: [TypeAccess] TestKt
|
||||
# 3| 0: [VarAccess] arr
|
||||
# 3| 1: [IntegerLiteral] 1
|
||||
# 3| 2: [IntegerLiteral] 2
|
||||
# 4| 2: [ExprStmt] <Expr>;
|
||||
# 4| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
|
||||
# 4| 0: [TypeAccess] Unit
|
||||
# 4| 1: [MethodAccess] get(...)
|
||||
# 4| -1: [VarAccess] mt
|
||||
# 4| 0: [IntegerLiteral] 1
|
||||
# 4| 1: [IntegerLiteral] 2
|
||||
# 7| 2: [ExtensionMethod] get
|
||||
# 7| 3: [TypeAccess] String
|
||||
#-----| 4: (Parameters)
|
||||
# 7| 0: [Parameter] <this>
|
||||
# 7| 0: [TypeAccess] byte[]
|
||||
# 7| 1: [Parameter] i
|
||||
# 7| 0: [TypeAccess] int
|
||||
# 7| 2: [Parameter] j
|
||||
# 7| 0: [TypeAccess] int
|
||||
# 7| 5: [BlockStmt] { ... }
|
||||
# 7| 0: [ReturnStmt] return ...
|
||||
# 7| 0: [StringLiteral]
|
||||
# 10| 2: [Class] C
|
||||
# 10| 1: [Constructor] C
|
||||
# 10| 5: [BlockStmt] { ... }
|
||||
# 10| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 10| 1: [BlockStmt] { ... }
|
||||
# 11| 2: [Method] get
|
||||
# 11| 3: [TypeAccess] String
|
||||
#-----| 4: (Parameters)
|
||||
# 11| 0: [Parameter] i
|
||||
# 11| 0: [TypeAccess] int
|
||||
# 11| 1: [Parameter] j
|
||||
# 11| 0: [TypeAccess] int
|
||||
# 11| 5: [BlockStmt] { ... }
|
||||
# 11| 0: [ReturnStmt] return ...
|
||||
# 11| 0: [StringLiteral]
|
||||
@@ -0,0 +1 @@
|
||||
semmle/code/java/PrintAst.ql
|
||||
12
java/ql/test/kotlin/library-tests/operator-overloads/test.kt
Normal file
12
java/ql/test/kotlin/library-tests/operator-overloads/test.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
fun fn(arr: ByteArray, mt: C) {
|
||||
arr[1]
|
||||
arr[1, 2]
|
||||
mt[1, 2]
|
||||
}
|
||||
|
||||
public operator fun ByteArray.get(i: Int, j: Int) = ""
|
||||
|
||||
|
||||
public class C {
|
||||
public operator fun get(i: Int, j: Int) = ""
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import java
|
||||
import java
|
||||
import semmle.code.java.Diagnostics
|
||||
|
||||
from Diagnostic d
|
||||
select d
|
||||
Reference in New Issue
Block a user