Skip to content

Commit b5f9fbe

Browse files
authored
Merge pull request #10228 from igfoo/igfoo/useSimpleType
Kotlin: Refactor useSimpleType to avoid some casts
2 parents da7d270 + a07be19 commit b5f9fbe

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,15 @@ open class KotlinUsesExtractor(
667667
dimensions++
668668
if (elementType.isPrimitiveArray())
669669
isPrimitiveArray = true
670-
if (((elementType as IrSimpleType).arguments.singleOrNull() as? IrTypeProjection)?.variance == Variance.IN_VARIANCE) {
671-
// Because Java's arrays are covariant, Kotlin will render Array<in X> as Object[], Array<Array<in X>> as Object[][] etc.
672-
componentType = replaceComponentTypeWithAny(s, dimensions - 1)
673-
elementType = pluginContext.irBuiltIns.anyType as IrSimpleType
674-
break
670+
if (elementType is IrSimpleType) {
671+
if ((elementType.arguments.singleOrNull() as? IrTypeProjection)?.variance == Variance.IN_VARIANCE) {
672+
// Because Java's arrays are covariant, Kotlin will render Array<in X> as Object[], Array<Array<in X>> as Object[][] etc.
673+
componentType = replaceComponentTypeWithAny(s, dimensions - 1)
674+
elementType = pluginContext.irBuiltIns.anyType
675+
break
676+
}
677+
} else {
678+
logger.warn("Unexpected element type representation ${elementType.javaClass} for ${s.render()}")
675679
}
676680
elementType = elementType.getArrayElementType(pluginContext.irBuiltIns)
677681
}

0 commit comments

Comments
 (0)