@@ -2613,8 +2613,12 @@ open class KotlinFileExtractor(
26132613 || isBuiltinCallKotlin(c, " byteArrayOf" )
26142614 || isBuiltinCallKotlin(c, " booleanArrayOf" ) -> {
26152615
2616- // TODO: is there any reason not to always use getArrayElementType?
2617- val elementType = if (isBuiltinCallKotlin(c, " arrayOf" )) {
2616+
2617+ val isPrimitiveArrayCreation = ! isBuiltinCallKotlin(c, " arrayOf" )
2618+ val elementType = if (isPrimitiveArrayCreation) {
2619+ c.type.getArrayElementType(pluginContext.irBuiltIns)
2620+ } else {
2621+ // TODO: is there any reason not to always use getArrayElementType?
26182622 if (c.typeArgumentsCount == 1 ) {
26192623 c.getTypeArgument(0 ).also {
26202624 if (it == null ) {
@@ -2625,8 +2629,6 @@ open class KotlinFileExtractor(
26252629 logger.errorElement(" Expected to find one type argument in arrayOf call" , c)
26262630 null
26272631 }
2628- } else {
2629- c.type.getArrayElementType(pluginContext.irBuiltIns)
26302632 }
26312633
26322634 val arg = if (c.valueArgumentsCount == 1 ) c.getValueArgument(0 ) else {
@@ -2639,7 +2641,7 @@ open class KotlinFileExtractor(
26392641 }
26402642 }
26412643
2642- extractArrayCreation(arg, c.type, elementType, c, parent, idx, callable, enclosingStmt)
2644+ extractArrayCreation(arg, c.type, elementType, isPrimitiveArrayCreation, c, parent, idx, callable, enclosingStmt)
26432645 }
26442646 isBuiltinCall(c, " <get-java>" , " kotlin.jvm" ) -> {
26452647 // Special case for KClass<*>.java, which is used in the Parcelize plugin. In normal cases, this is already rewritten to the property referenced below:
@@ -2825,7 +2827,7 @@ open class KotlinFileExtractor(
28252827 }
28262828 }
28272829
2828- private fun extractArrayCreation (elementList : IrVararg ? , resultType : IrType , elementType : IrType ? , locElement : IrElement , parent : Label <out DbExprparent >, idx : Int , enclosingCallable : Label <out DbCallable >, enclosingStmt : Label <out DbStmt >) {
2830+ private fun extractArrayCreation (elementList : IrVararg ? , resultType : IrType , elementType : IrType ? , allowPrimitiveElementType : Boolean , locElement : IrElement , parent : Label <out DbExprparent >, idx : Int , enclosingCallable : Label <out DbCallable >, enclosingStmt : Label <out DbStmt >) {
28292831 // If this is [someType]ArrayOf(*x), x, otherwise null
28302832 val clonedArray = elementList?.let {
28312833 if (it.elements.size == 1 ) {
@@ -2852,7 +2854,8 @@ open class KotlinFileExtractor(
28522854 tw.writeCallableEnclosingExpr(id, enclosingCallable)
28532855
28542856 if (elementType != null ) {
2855- extractTypeAccessRecursive(elementType, locId, id, - 1 , enclosingCallable, enclosingStmt, TypeContext .GENERIC_ARGUMENT )
2857+ val typeContext = if (allowPrimitiveElementType) TypeContext .OTHER else TypeContext .GENERIC_ARGUMENT
2858+ extractTypeAccessRecursive(elementType, locId, id, - 1 , enclosingCallable, enclosingStmt, typeContext)
28562859 }
28572860
28582861 if (elementList != null ) {
@@ -3657,7 +3660,7 @@ open class KotlinFileExtractor(
36573660 // This AST element can also occur as a collection literal in an annotation class, such as
36583661 // annotation class Ann(val strings: Array<String> = [])
36593662 val exprParent = parent.expr(e, callable)
3660- extractArrayCreation(e, e.type, e.varargElementType, e, exprParent.parent, exprParent.idx, callable, exprParent.enclosingStmt)
3663+ extractArrayCreation(e, e.type, e.varargElementType, true , e, exprParent.parent, exprParent.idx, callable, exprParent.enclosingStmt)
36613664 }
36623665 is IrGetObjectValue -> {
36633666 // For `object MyObject { ... }`, the .class has an
0 commit comments