@@ -239,8 +239,6 @@ open class KotlinUsesExtractor(
239239 return UseClassInstanceResult (classTypeResult, extractClass)
240240 }
241241
242- private fun isArray (t : IrSimpleType ) = t.isBoxedArray || t.isPrimitiveArray()
243-
244242 private fun extractClassLaterIfExternal (c : IrClass ) {
245243 if (isExternalDeclaration(c)) {
246244 extractExternalClassLater(c)
@@ -551,6 +549,22 @@ open class KotlinUsesExtractor(
551549 )
552550 }
553551
552+ /*
553+ Kotlin arrays can be broken down as:
554+
555+ isArray(t)
556+ |- t.isBoxedArray
557+ | |- t.isArray() e.g. Array<Boolean>, Array<Boolean?>
558+ | |- t.isNullableArray() e.g. Array<Boolean>?, Array<Boolean?>?
559+ |- t.isPrimitiveArray() e.g. BooleanArray
560+
561+ For the corresponding Java types:
562+ Boxed arrays are represented as e.g. java.lang.Boolean[].
563+ Primitive arrays are represented as e.g. boolean[].
564+ */
565+
566+ private fun isArray (t : IrType ) = t.isBoxedArray || t.isPrimitiveArray()
567+
554568 data class ArrayInfo (val elementTypeResults : TypeResults ,
555569 val componentTypeResults : TypeResults ,
556570 val dimensions : Int )
@@ -565,7 +579,7 @@ open class KotlinUsesExtractor(
565579 */
566580 private fun useArrayType (t : IrType , isPrimitiveArray : Boolean ): ArrayInfo {
567581
568- if (! t.isBoxedArray && ! t.isPrimitiveArray( )) {
582+ if (! isArray(t )) {
569583 val nullableT = if (t.isPrimitiveType() && ! isPrimitiveArray) t.makeNullable() else t
570584 val typeResults = useType(nullableT)
571585 return ArrayInfo (typeResults, typeResults, 0 )
@@ -1141,13 +1155,13 @@ open class KotlinUsesExtractor(
11411155 }
11421156 } else {
11431157 t.classOrNull?.let { tCls ->
1144- if (t.isArray() || t.isNullableArray() ) {
1158+ if (t.isBoxedArray ) {
11451159 (t.arguments.singleOrNull() as ? IrTypeProjection )?.let { elementTypeArg ->
11461160 val elementType = elementTypeArg.type
11471161 val replacedElementType = kClassToJavaClass(elementType)
11481162 if (replacedElementType != = elementType) {
11491163 val newArg = makeTypeProjection(replacedElementType, elementTypeArg.variance)
1150- return tCls.typeWithArguments(listOf (newArg)).codeQlWithHasQuestionMark(t.isNullableArray ())
1164+ return tCls.typeWithArguments(listOf (newArg)).codeQlWithHasQuestionMark(t.isNullable ())
11511165 }
11521166 }
11531167 }
@@ -1578,7 +1592,7 @@ open class KotlinUsesExtractor(
15781592 }
15791593
15801594 if (owner is IrClass ) {
1581- if (t.isArray() || t.isNullableArray() ) {
1595+ if (t.isBoxedArray ) {
15821596 val elementType = t.getArrayElementType(pluginContext.irBuiltIns)
15831597 val erasedElementType = erase(elementType)
15841598 return owner.typeWith(erasedElementType).codeQlWithHasQuestionMark(t.isNullable())
0 commit comments