mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Array types: distinguish (e.g.) Array<Int> from IntArray
This commit is contained in:
committed by
Ian Lynagh
parent
380da465b9
commit
70294bd26b
@@ -410,7 +410,11 @@ open class KotlinUsesExtractor(
|
||||
else
|
||||
primitiveInfo.primitiveName
|
||||
|
||||
type.isBoxedArray || type.isPrimitiveArray() -> shortName(type.getArrayElementType(pluginContext.irBuiltIns)) + "[]"
|
||||
type.isBoxedArray || type.isPrimitiveArray() -> {
|
||||
val elementType = type.getArrayElementType(pluginContext.irBuiltIns)
|
||||
val javaElementType = if (type.isPrimitiveArray()) elementType else elementType.makeNullable()
|
||||
shortName(javaElementType) + "[]"
|
||||
}
|
||||
|
||||
type.classifier.owner is IrClass -> {
|
||||
val c = type.classifier.owner as IrClass
|
||||
@@ -549,7 +553,8 @@ open class KotlinUsesExtractor(
|
||||
// Note the stripping of any type projection from `componentType` here mirrors the action of `IrType.getArrayElementType`,
|
||||
// and is required if we are not to produce different kotlin types for the same Java type (e.g. List[] -> Array<out List> or Array<List>)
|
||||
val owner: IrClass = arrayType.classifier.owner as IrClass
|
||||
val kotlinClassName = getUnquotedClassLabel(owner, listOf(makeTypeProjection(componentType, Variance.INVARIANT)))
|
||||
val kotlinTypeArgs = if (arrayType.arguments.isEmpty()) listOf() else listOf(makeTypeProjection(componentType, Variance.INVARIANT))
|
||||
val kotlinClassName = getUnquotedClassLabel(owner, kotlinTypeArgs)
|
||||
val kotlinSignature = "$javaSignature?" // TODO: Wrong
|
||||
val kotlinLabel = "@\"kt_type;nullable;${kotlinClassName}\""
|
||||
val kotlinId: Label<DbKt_nullable_type> = tw.getLabelFor(kotlinLabel, {
|
||||
@@ -557,14 +562,11 @@ open class KotlinUsesExtractor(
|
||||
})
|
||||
val kotlinResult = TypeResult(kotlinId, kotlinSignature)
|
||||
|
||||
/*
|
||||
TODO
|
||||
tw.getLabelFor<DbMethod>("@\"callable;{$id}.clone(){$id}\"") {
|
||||
tw.writeMethods(it, "clone", "clone()", javaResult.id, kotlinResult.id, javaResult.id, it)
|
||||
// TODO: modifiers
|
||||
// tw.writeHasModifier(clone, getModifierKey("public"))
|
||||
}
|
||||
*/
|
||||
|
||||
return TypeResults(javaResult, kotlinResult)
|
||||
}
|
||||
@@ -657,19 +659,22 @@ class X {
|
||||
|
||||
(s.isBoxedArray && s.arguments.isNotEmpty()) || s.isPrimitiveArray() -> {
|
||||
var dimensions = 1
|
||||
var isPrimitiveArray = s.isPrimitiveArray()
|
||||
val componentType = s.getArrayElementType(pluginContext.irBuiltIns)
|
||||
var elementType = componentType
|
||||
while (elementType.isBoxedArray || elementType.isPrimitiveArray()) {
|
||||
dimensions++
|
||||
if(elementType.isPrimitiveArray())
|
||||
isPrimitiveArray = true
|
||||
elementType = elementType.getArrayElementType(pluginContext.irBuiltIns)
|
||||
}
|
||||
|
||||
fun nullableIfRefType(type: IrType) = if (type.isPrimitiveType()) type else type.makeNullable()
|
||||
fun nullableUnlessPrimitive(type: IrType) = if (isPrimitiveArray && type.isPrimitiveType()) type else type.makeNullable()
|
||||
|
||||
return useArrayType(
|
||||
s,
|
||||
nullableIfRefType(componentType),
|
||||
nullableIfRefType(elementType),
|
||||
nullableUnlessPrimitive(componentType),
|
||||
nullableUnlessPrimitive(elementType),
|
||||
dimensions
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
class Test {
|
||||
|
||||
fun test(a: Array<Int>, b: Array<Int?>, c: IntArray, d: Array<Array<Int?>>, e: Array<Array<Int>>, f: Array<IntArray>) { }
|
||||
|
||||
}
|
||||
6
java/ql/test/kotlin/library-tests/arrays/test.expected
Normal file
6
java/ql/test/kotlin/library-tests/arrays/test.expected
Normal file
@@ -0,0 +1,6 @@
|
||||
| primitiveArrays.kt:5:12:5:24 | a | file://:0:0:0:0 | Integer[] | file://:0:0:0:0 | Integer | file://:0:0:0:0 | Integer | file://:0:0:0:0 | Kotlin nullable Integer | file://:0:0:0:0 | Kotlin nullable Integer |
|
||||
| primitiveArrays.kt:5:27:5:40 | b | file://:0:0:0:0 | Integer[] | file://:0:0:0:0 | Integer | file://:0:0:0:0 | Integer | file://:0:0:0:0 | Kotlin nullable Integer | file://:0:0:0:0 | Kotlin nullable Integer |
|
||||
| primitiveArrays.kt:5:43:5:53 | c | file://:0:0:0:0 | int[] | file://:0:0:0:0 | int | file://:0:0:0:0 | int | file://:0:0:0:0 | Kotlin not-null Integer | file://:0:0:0:0 | Kotlin not-null Integer |
|
||||
| primitiveArrays.kt:5:56:5:76 | d | file://:0:0:0:0 | Integer[][] | file://:0:0:0:0 | Integer[] | file://:0:0:0:0 | Integer | file://:0:0:0:0 | Kotlin nullable Integer[] | file://:0:0:0:0 | Kotlin nullable Integer |
|
||||
| primitiveArrays.kt:5:79:5:98 | e | file://:0:0:0:0 | Integer[][] | file://:0:0:0:0 | Integer[] | file://:0:0:0:0 | Integer | file://:0:0:0:0 | Kotlin nullable Integer[] | file://:0:0:0:0 | Kotlin nullable Integer |
|
||||
| primitiveArrays.kt:5:101:5:118 | f | file://:0:0:0:0 | int[][] | file://:0:0:0:0 | int[] | file://:0:0:0:0 | int | file://:0:0:0:0 | Kotlin nullable int[] | file://:0:0:0:0 | Kotlin not-null Integer |
|
||||
5
java/ql/test/kotlin/library-tests/arrays/test.ql
Normal file
5
java/ql/test/kotlin/library-tests/arrays/test.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import java
|
||||
|
||||
from Parameter p, Array a
|
||||
where p.getType() = a and p.getFile().getBaseName() = "primitiveArrays.kt"
|
||||
select p, a, a.getComponentType(), a.getElementType(), a.getComponentKotlinType(), a.getElementKotlinType()
|
||||
Reference in New Issue
Block a user