Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

ClassCastException: org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl cannot be cast to org.jetbrains.kotlin.ir.expressions.IrCall #1779

Closed
soywiz opened this issue Jul 8, 2018 · 1 comment
Assignees

Comments

@soywiz
Copy link
Contributor

soywiz commented Jul 8, 2018

https://github.com/kpspemu/kpspemu/blob/edd812e5ff4abc0f4c196add1ac46853612be603/kpspemu/common/src/com/soywiz/kpspemu/ge/GeEnums.kt#L227

 * Compiler version info: Konan: 0.9-dev / Kotlin: 1.2.70
 * Output kind: PROGRAM

exception: java.lang.ClassCastException: org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl cannot be cast to org.jetbrains.kotlin.ir.expressions.IrCall
        at org.jetbrains.kotlin.backend.konan.lower.EnumClassLowering$EnumClassTransformer.createSyntheticValuesPropertyDeclaration(EnumClassLowering.kt:336)
        at org.jetbrains.kotlin.backend.konan.lower.EnumClassLowering$EnumClassTransformer.createImplObject(EnumClassLowering.kt:319)
        at org.jetbrains.kotlin.backend.konan.lower.EnumClassLowering$EnumClassTransformer.run(EnumClassLowering.kt:197)
        at org.jetbrains.kotlin.backend.konan.lower.EnumClassLowering.lower(EnumClassLowering.kt:173)
        at org.jetbrains.kotlin.backend.common.LowerKt$runOnFilePostfix$1.visitClass(Lower.kt:57)
        at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitClass(IrElementVisitorVoid.kt:44)
        at org.jetbrains.kotlin.backend.common.LowerKt$runOnFilePostfix$1.visitClass(Lower.kt:50)
        at org.jetbrains.kotlin.backend.common.LowerKt$runOnFilePostfix$1.visitClass(Lower.kt:50)
        at org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl.accept(IrClassImpl.kt:100)
        at org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl.acceptChildren(IrFileImpl.kt:79)
        at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptChildrenVoid(IrElementVisitorVoid.kt:251)
        at org.jetbrains.kotlin.backend.common.LowerKt$runOnFilePostfix$1.visitElement(Lower.kt:52)
        at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitPackageFragment(IrElementVisitorVoid.kt:30)
        at org.jetbrains.kotlin.backend.common.LowerKt$runOnFilePostfix$1.visitPackageFragment(Lower.kt:50)
        at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitFile(IrElementVisitorVoid.kt:37)

After adding a few prints and compiling from source, I identified the problematic enum. Circumvented the error like this:

enum class PixelFormat(
    override val id: Int,
    val bytesPerPixel: Double,
    val colorFormat: ColorFormat? = null,
    val isRgba: Boolean = false,
    val isPalette: Boolean = false,
    val colorBits: Int = 0,
    val paletteBits: Int = 0,
    val dxtVersion: Int = 0,
    val isCompressed: Boolean = false
) : IdEnum {
    RGBA_5650(0, bytesPerPixel = 2.0, colorFormat = PspRGB_565, isRgba = true, colorBits = 16),
    RGBA_5551(1, bytesPerPixel = 2.0, colorFormat = PspRGBA_5551, isRgba = true, colorBits = 16),
    RGBA_4444(2, bytesPerPixel = 2.0, colorFormat = com.soywiz.korim.color.RGBA_4444, isRgba = true, colorBits = 16),
    RGBA_8888(3, bytesPerPixel = 4.0, colorFormat = com.soywiz.korim.color.RGBA, isRgba = true, colorBits = 32),
    PALETTE_T4(4, bytesPerPixel = 0.5, isPalette = true, paletteBits = 4),
    PALETTE_T8(5, bytesPerPixel = 1.0, isPalette = true, paletteBits = 8),
    PALETTE_T16(6, bytesPerPixel = 2.0, isPalette = true, paletteBits = 16),
    PALETTE_T32(7, bytesPerPixel = 4.0, isPalette = true, paletteBits = 32),
    COMPRESSED_DXT1(8, bytesPerPixel = 0.5, isCompressed = true, dxtVersion = 1),
    COMPRESSED_DXT3(9, bytesPerPixel = 1.0, isCompressed = true, dxtVersion = 3),
    COMPRESSED_DXT5(10, bytesPerPixel = 1.0, isCompressed = true, dxtVersion = 5);

    val bitsPerPixel = (bytesPerPixel * 8).toInt()

    val requireClut: Boolean = isPalette
    fun getSizeInBytes(count: Int): Int = (bytesPerPixel * count).toInt()

    companion object : IdEnum.SmallCompanion<PixelFormat>(values())
}

-->

enum class PixelFormat(
    override val id: Int,
    val bytesPerPixel: Double,
    val isRgba: Boolean = false,
    val isPalette: Boolean = false,
    val colorBits: Int = 0,
    val paletteBits: Int = 0,
    val dxtVersion: Int = 0,
    val isCompressed: Boolean = false
) : IdEnum {
    RGBA_5650(0, 2.0, true, false, 16, 0, 0, false),
    RGBA_5551(1, 2.0, true, false, 16, 0, 0, false),
    RGBA_4444(2, 2.0, true, false, 16, 0, 0, false),
    RGBA_8888(3, 4.0, true, false, 32, 0, 0, false),
    PALETTE_T4(4, 0.5, false,  true, 0, 4, 0, false),
    PALETTE_T8(5, 1.0, false,  true, 0, 8, 0, false),
    PALETTE_T16(6, 2.0, false, true, 0, 16, 0, false),
    PALETTE_T32(7, 4.0, false, true, 0, 32, 0, false),
    COMPRESSED_DXT1(8, 0.5, false,  false, 0, 0, 1, true),
    COMPRESSED_DXT3(9, 1.0, false,  false, 0, 0, 3, true),
    COMPRESSED_DXT5(10, 1.0, false, false, 0, 0, 5, true);

    val bitsPerPixel get() = (bytesPerPixel * 8).toInt()

    val requireClut: Boolean get() = isPalette
    fun getSizeInBytes(count: Int): Int = (bytesPerPixel * count).toInt()

    val colorFormat: ColorFormat?
        get() = when (this) {
            RGBA_5650 -> PspRGB_565
            RGBA_5551 -> PspRGBA_5551
            RGBA_4444 -> com.soywiz.korim.color.RGBA_4444
            RGBA_8888 -> com.soywiz.korim.color.RGBA
            else -> null
        }

    companion object : IdEnum.SmallCompanion<PixelFormat>(values())
}
soywiz added a commit to soywiz-archive/kpspemu that referenced this issue Jul 8, 2018
@ilmat192 ilmat192 self-assigned this Jul 10, 2018
@ilmat192
Copy link
Contributor

Fixed by #1794. The issue relates to reordering named arguments, so to avoid it in 0.8, you just need to create an enum entry keeping the argument order of the enum constructor:

enum class PixelFormat(
    ...
    val dxtVersion: Int = 0,
    val isCompressed: Boolean = false
) : IdEnum {
    ...
    //  Keep the same order as in the PixelFormat constructor.
    COMPRESSED_DXT5(10, bytesPerPixel = 1.0, dxtVersion = 5, isCompressed = true);
    ...
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants