@@ -239,8 +239,6 @@ open class KotlinUsesExtractor(
239
239
return UseClassInstanceResult (classTypeResult, extractClass)
240
240
}
241
241
242
- private fun isArray (t : IrSimpleType ) = t.isBoxedArray || t.isPrimitiveArray()
243
-
244
242
private fun extractClassLaterIfExternal (c : IrClass ) {
245
243
if (isExternalDeclaration(c)) {
246
244
extractExternalClassLater(c)
@@ -551,6 +549,22 @@ open class KotlinUsesExtractor(
551
549
)
552
550
}
553
551
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
+
554
568
data class ArrayInfo (val elementTypeResults : TypeResults ,
555
569
val componentTypeResults : TypeResults ,
556
570
val dimensions : Int )
@@ -565,7 +579,7 @@ open class KotlinUsesExtractor(
565
579
*/
566
580
private fun useArrayType (t : IrType , isPrimitiveArray : Boolean ): ArrayInfo {
567
581
568
- if (! t.isBoxedArray && ! t.isPrimitiveArray( )) {
582
+ if (! isArray(t )) {
569
583
val nullableT = if (t.isPrimitiveType() && ! isPrimitiveArray) t.makeNullable() else t
570
584
val typeResults = useType(nullableT)
571
585
return ArrayInfo (typeResults, typeResults, 0 )
@@ -1141,13 +1155,13 @@ open class KotlinUsesExtractor(
1141
1155
}
1142
1156
} else {
1143
1157
t.classOrNull?.let { tCls ->
1144
- if (t.isArray() || t.isNullableArray() ) {
1158
+ if (t.isBoxedArray ) {
1145
1159
(t.arguments.singleOrNull() as ? IrTypeProjection )?.let { elementTypeArg ->
1146
1160
val elementType = elementTypeArg.type
1147
1161
val replacedElementType = kClassToJavaClass(elementType)
1148
1162
if (replacedElementType != = elementType) {
1149
1163
val newArg = makeTypeProjection(replacedElementType, elementTypeArg.variance)
1150
- return tCls.typeWithArguments(listOf (newArg)).codeQlWithHasQuestionMark(t.isNullableArray ())
1164
+ return tCls.typeWithArguments(listOf (newArg)).codeQlWithHasQuestionMark(t.isNullable ())
1151
1165
}
1152
1166
}
1153
1167
}
@@ -1578,7 +1592,7 @@ open class KotlinUsesExtractor(
1578
1592
}
1579
1593
1580
1594
if (owner is IrClass ) {
1581
- if (t.isArray() || t.isNullableArray() ) {
1595
+ if (t.isBoxedArray ) {
1582
1596
val elementType = t.getArrayElementType(pluginContext.irBuiltIns)
1583
1597
val erasedElementType = erase(elementType)
1584
1598
return owner.typeWith(erasedElementType).codeQlWithHasQuestionMark(t.isNullable())
0 commit comments