mirror of
https://github.com/github/codeql.git
synced 2025-12-22 03:36:30 +01:00
Merge pull request #13148 from igfoo/igfoo/arrays
Kotlin: Add some documentation on arrays, and tweak the tests we use for them
This commit is contained in:
@@ -239,8 +239,6 @@ open class KotlinUsesExtractor(
|
||||
return UseClassInstanceResult(classTypeResult, extractClass)
|
||||
}
|
||||
|
||||
private fun isArray(t: IrSimpleType) = t.isBoxedArray || t.isPrimitiveArray()
|
||||
|
||||
private fun extractClassLaterIfExternal(c: IrClass) {
|
||||
if (isExternalDeclaration(c)) {
|
||||
extractExternalClassLater(c)
|
||||
@@ -551,6 +549,22 @@ open class KotlinUsesExtractor(
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
Kotlin arrays can be broken down as:
|
||||
|
||||
isArray(t)
|
||||
|- t.isBoxedArray
|
||||
| |- t.isArray() e.g. Array<Boolean>, Array<Boolean?>
|
||||
| |- t.isNullableArray() e.g. Array<Boolean>?, Array<Boolean?>?
|
||||
|- t.isPrimitiveArray() e.g. BooleanArray
|
||||
|
||||
For the corresponding Java types:
|
||||
Boxed arrays are represented as e.g. java.lang.Boolean[].
|
||||
Primitive arrays are represented as e.g. boolean[].
|
||||
*/
|
||||
|
||||
private fun isArray(t: IrType) = t.isBoxedArray || t.isPrimitiveArray()
|
||||
|
||||
data class ArrayInfo(val elementTypeResults: TypeResults,
|
||||
val componentTypeResults: TypeResults,
|
||||
val dimensions: Int)
|
||||
@@ -565,7 +579,7 @@ open class KotlinUsesExtractor(
|
||||
*/
|
||||
private fun useArrayType(t: IrType, isPrimitiveArray: Boolean): ArrayInfo {
|
||||
|
||||
if (!t.isBoxedArray && !t.isPrimitiveArray()) {
|
||||
if (!isArray(t)) {
|
||||
val nullableT = if (t.isPrimitiveType() && !isPrimitiveArray) t.makeNullable() else t
|
||||
val typeResults = useType(nullableT)
|
||||
return ArrayInfo(typeResults, typeResults, 0)
|
||||
@@ -1141,13 +1155,13 @@ open class KotlinUsesExtractor(
|
||||
}
|
||||
} else {
|
||||
t.classOrNull?.let { tCls ->
|
||||
if (t.isArray() || t.isNullableArray()) {
|
||||
if (t.isBoxedArray) {
|
||||
(t.arguments.singleOrNull() as? IrTypeProjection)?.let { elementTypeArg ->
|
||||
val elementType = elementTypeArg.type
|
||||
val replacedElementType = kClassToJavaClass(elementType)
|
||||
if (replacedElementType !== elementType) {
|
||||
val newArg = makeTypeProjection(replacedElementType, elementTypeArg.variance)
|
||||
return tCls.typeWithArguments(listOf(newArg)).codeQlWithHasQuestionMark(t.isNullableArray())
|
||||
return tCls.typeWithArguments(listOf(newArg)).codeQlWithHasQuestionMark(t.isNullable())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1578,7 +1592,7 @@ open class KotlinUsesExtractor(
|
||||
}
|
||||
|
||||
if (owner is IrClass) {
|
||||
if (t.isArray() || t.isNullableArray()) {
|
||||
if (t.isBoxedArray) {
|
||||
val elementType = t.getArrayElementType(pluginContext.irBuiltIns)
|
||||
val erasedElementType = erase(elementType)
|
||||
return owner.typeWith(erasedElementType).codeQlWithHasQuestionMark(t.isNullable())
|
||||
|
||||
Reference in New Issue
Block a user