@@ -410,7 +410,11 @@ open class KotlinUsesExtractor(
410410 else
411411 primitiveInfo.primitiveName
412412
413- type.isBoxedArray || type.isPrimitiveArray() -> shortName(type.getArrayElementType(pluginContext.irBuiltIns)) + " []"
413+ type.isBoxedArray || type.isPrimitiveArray() -> {
414+ val elementType = type.getArrayElementType(pluginContext.irBuiltIns)
415+ val javaElementType = if (type.isPrimitiveArray()) elementType else elementType.makeNullable()
416+ shortName(javaElementType) + " []"
417+ }
414418
415419 type.classifier.owner is IrClass -> {
416420 val c = type.classifier.owner as IrClass
@@ -549,22 +553,20 @@ open class KotlinUsesExtractor(
549553 // Note the stripping of any type projection from `componentType` here mirrors the action of `IrType.getArrayElementType`,
550554 // 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>)
551555 val owner: IrClass = arrayType.classifier.owner as IrClass
552- val kotlinClassName = getUnquotedClassLabel(owner, listOf (makeTypeProjection(componentType, Variance .INVARIANT )))
556+ val kotlinTypeArgs = if (arrayType.arguments.isEmpty()) listOf () else listOf (makeTypeProjection(componentType, Variance .INVARIANT ))
557+ val kotlinClassName = getUnquotedClassLabel(owner, kotlinTypeArgs)
553558 val kotlinSignature = " $javaSignature ?" // TODO: Wrong
554559 val kotlinLabel = " @\" kt_type;nullable;${kotlinClassName} \" "
555560 val kotlinId: Label <DbKt_nullable_type > = tw.getLabelFor(kotlinLabel, {
556561 tw.writeKt_nullable_types(it, id)
557562 })
558563 val kotlinResult = TypeResult (kotlinId, kotlinSignature)
559564
560- /*
561- TODO
562565 tw.getLabelFor<DbMethod >(" @\" callable;{$id }.clone(){$id }\" " ) {
563566 tw.writeMethods(it, " clone" , " clone()" , javaResult.id, kotlinResult.id, javaResult.id, it)
564567 // TODO: modifiers
565568 // tw.writeHasModifier(clone, getModifierKey("public"))
566569 }
567- */
568570
569571 return TypeResults (javaResult, kotlinResult)
570572 }
@@ -657,19 +659,22 @@ class X {
657659
658660 (s.isBoxedArray && s.arguments.isNotEmpty()) || s.isPrimitiveArray() -> {
659661 var dimensions = 1
662+ var isPrimitiveArray = s.isPrimitiveArray()
660663 val componentType = s.getArrayElementType(pluginContext.irBuiltIns)
661664 var elementType = componentType
662665 while (elementType.isBoxedArray || elementType.isPrimitiveArray()) {
663666 dimensions++
667+ if (elementType.isPrimitiveArray())
668+ isPrimitiveArray = true
664669 elementType = elementType.getArrayElementType(pluginContext.irBuiltIns)
665670 }
666671
667- fun nullableIfRefType (type : IrType ) = if (type.isPrimitiveType()) type else type.makeNullable()
672+ fun nullableUnlessPrimitive (type : IrType ) = if (isPrimitiveArray && type.isPrimitiveType()) type else type.makeNullable()
668673
669674 return useArrayType(
670675 s,
671- nullableIfRefType (componentType),
672- nullableIfRefType (elementType),
676+ nullableUnlessPrimitive (componentType),
677+ nullableUnlessPrimitive (elementType),
673678 dimensions
674679 )
675680 }
0 commit comments