Kotlin: Refactor useSimpleType to avoid some casts

This commit is contained in:
Ian Lynagh
2022-08-30 17:55:57 +01:00
parent f5d43b80ed
commit a07be192fa

View File

@@ -667,12 +667,16 @@ open class KotlinUsesExtractor(
dimensions++ dimensions++
if (elementType.isPrimitiveArray()) if (elementType.isPrimitiveArray())
isPrimitiveArray = true isPrimitiveArray = true
if (((elementType as IrSimpleType).arguments.singleOrNull() as? IrTypeProjection)?.variance == Variance.IN_VARIANCE) { if (elementType is IrSimpleType) {
if ((elementType.arguments.singleOrNull() as? IrTypeProjection)?.variance == Variance.IN_VARIANCE) {
// Because Java's arrays are covariant, Kotlin will render Array<in X> as Object[], Array<Array<in X>> as Object[][] etc. // Because Java's arrays are covariant, Kotlin will render Array<in X> as Object[], Array<Array<in X>> as Object[][] etc.
componentType = replaceComponentTypeWithAny(s, dimensions - 1) componentType = replaceComponentTypeWithAny(s, dimensions - 1)
elementType = pluginContext.irBuiltIns.anyType as IrSimpleType elementType = pluginContext.irBuiltIns.anyType
break break
} }
} else {
logger.warn("Unexpected element type representation ${elementType.javaClass} for ${s.render()}")
}
elementType = elementType.getArrayElementType(pluginContext.irBuiltIns) elementType = elementType.getArrayElementType(pluginContext.irBuiltIns)
} }