Kotlinx.serialization: UnsupportedOperationException: IrValueParameterImpl upgrading to Kotlin 1.3.30

Created on 16 Apr 2019  路  7Comments  路  Source: Kotlin/kotlinx.serialization

After upgrading from Kotlin 1.3.21 (gradle 4.10.2) to 1.3.30 (gradle 5.1.1), we get this exception building (at one of the link stages) for iOS sim (iOSX64):

> Task :linkTestDebugExecutableIosSim
e: Compilation failed: org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl@37a28e2c

 * Source files: <redacted>
 * Compiler version info: Konan: 1.2 / Kotlin: 1.3.30
 * Output kind: PROGRAM

e: java.lang.UnsupportedOperationException: org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl@37a28e2c
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$TopLevelCodeContext.unsupported(IrToBitcode.kt:242)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$TopLevelCodeContext.genGetValue(IrToBitcode.kt:258)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$TopLevelCodeContext.genGetValue(IrToBitcode.kt:241)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$InnerScope.genGetValue(IrToBitcode.kt)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$InnerScope.genGetValue(IrToBitcode.kt)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$InnerScope.genGetValue(IrToBitcode.kt)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$InnerScope.genGetValue(IrToBitcode.kt)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$InnerScope.genGetValue(IrToBitcode.kt)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$InnerScope.genGetValue(IrToBitcode.kt)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$ParameterScope.genGetValue(IrToBitcode.kt:577)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$InnerScope.genGetValue(IrToBitcode.kt)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$VariableScope.genGetValue(IrToBitcode.kt:545)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$InnerScope.genGetValue(IrToBitcode.kt)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$VariableScope.genGetValue(IrToBitcode.kt:545)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateGetValue(IrToBitcode.kt:1164)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:762)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExplicitArgs(IrToBitcode.kt:1890)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateCall(IrToBitcode.kt:1741)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:757)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExplicitArgs(IrToBitcode.kt:1890)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateCall(IrToBitcode.kt:1741)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:757)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExplicitArgs(IrToBitcode.kt:1890)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateCall(IrToBitcode.kt:1741)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:757)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.generateVariable(IrToBitcode.kt:1216)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.generateStatement(IrToBitcode.kt:795)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateContainerExpression(IrToBitcode.kt:1715)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:772)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExplicitArgs(IrToBitcode.kt:1890)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateCall(IrToBitcode.kt:1741)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:757)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExplicitArgs(IrToBitcode.kt:1890)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateCall(IrToBitcode.kt:1741)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:757)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExplicitArgs(IrToBitcode.kt:1890)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateCall(IrToBitcode.kt:1741)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:757)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.generateWhenCase(IrToBitcode.kt:1092)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateWhen(IrToBitcode.kt:1073)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:768)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.generateWhenCase(IrToBitcode.kt:1092)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateWhen(IrToBitcode.kt:1073)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:768)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.generateStatement(IrToBitcode.kt:794)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitFunction(IrToBitcode.kt:672)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitSimpleFunction(IrElementVisitorVoid.kt:52)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitSimpleFunction(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitSimpleFunction(IrElementVisitorVoid.kt:53)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitSimpleFunction(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitSimpleFunction(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl.accept(IrFunctionImpl.kt:92)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptVoid(IrElementVisitorVoid.kt:258)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitClass(IrToBitcode.kt:712)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitClass(IrElementVisitorVoid.kt:44)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitClass(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitClass(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl.accept(IrClassImpl.kt:108)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptVoid(IrElementVisitorVoid.kt:258)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitClass(IrToBitcode.kt:712)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitClass(IrElementVisitorVoid.kt:44)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitClass(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitClass(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl.accept(IrClassImpl.kt:108)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptVoid(IrElementVisitorVoid.kt:258)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitClass(IrToBitcode.kt:712)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitClass(IrElementVisitorVoid.kt:44)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitClass(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitClass(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl.accept(IrClassImpl.kt:108)
    at org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl.acceptChildren(IrFileImpl.kt:82)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptChildrenVoid(IrElementVisitorVoid.kt:262)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitFile(IrToBitcode.kt:457)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitFile(IrElementVisitorVoid.kt:38)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitFile(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitFile(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl.accept(IrFileImpl.kt:79)
    at org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl.acceptChildren(IrModuleFragmentImpl.kt:45)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptChildrenVoid(IrElementVisitorVoid.kt:262)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitModuleFragment(IrToBitcode.kt:314)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitModuleFragment(IrElementVisitorVoid.kt:28)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitModuleFragment(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitModuleFragment(IrToBitcode.kt:201)
    at org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl.accept(IrModuleFragmentImpl.kt:42)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptVoid(IrElementVisitorVoid.kt:258)
    at org.jetbrains.kotlin.backend.konan.llvm.BitcodePhasesKt$codegenPhase$1.invoke(BitcodePhases.kt:134)
    at org.jetbrains.kotlin.backend.konan.llvm.BitcodePhasesKt$codegenPhase$1.invoke(BitcodePhases.kt)
    at org.jetbrains.kotlin.backend.konan.KonanLoweringPhasesKt$makeKonanModuleOpPhase$1.invoke(KonanLoweringPhases.kt:55)
    at org.jetbrains.kotlin.backend.konan.KonanLoweringPhasesKt$makeKonanModuleOpPhase$1.invoke(KonanLoweringPhases.kt:53)
    at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper$runBody$1.invoke(CompilerPhase.kt:91)
    at org.jetbrains.kotlin.backend.common.phaser.CompilerPhaseKt.downlevel(CompilerPhase.kt:18)
    at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.runBody(CompilerPhase.kt:90)
    at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.invoke(CompilerPhase.kt:73)
    at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$then$1.invoke(PhaseBuilders.kt:15)
    at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$then$1.invoke(PhaseBuilders.kt:14)
    at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$then$1.invoke(PhaseBuilders.kt:14)
    at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper$runBody$1.invoke(CompilerPhase.kt:91)
    at org.jetbrains.kotlin.backend.common.phaser.CompilerPhaseKt.downlevel(CompilerPhase.kt:18)
    at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.runBody(CompilerPhase.kt:90)
    at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.invoke(CompilerPhase.kt:73)
    at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$then$1.invoke(PhaseBuilders.kt:15)
    at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$then$1.invoke(PhaseBuilders.kt:14)
    at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$then$1.invoke(PhaseBuilders.kt:14)
    at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$then$1.invoke(PhaseBuilders.kt:14)
    at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$then$1.invoke(PhaseBuilders.kt:14)
    at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper$runBody$1.invoke(CompilerPhase.kt:91)
    at org.jetbrains.kotlin.backend.common.phaser.CompilerPhaseKt.downlevel(CompilerPhase.kt:18)
    at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.runBody(CompilerPhase.kt:90)
    at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.invoke(CompilerPhase.kt:73)
    at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$then$1.invoke(PhaseBuilders.kt:15)
    at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$then$1.invoke(PhaseBuilders.kt:14)
    at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper$runBody$1.invoke(CompilerPhase.kt:91)
    at org.jetbrains.kotlin.backend.common.phaser.CompilerPhaseKt.downlevel(CompilerPhase.kt:18)
    at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.runBody(CompilerPhase.kt:90)
    at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.invoke(CompilerPhase.kt:73)
    at org.jetbrains.kotlin.backend.common.phaser.CompilerPhaseKt.invokeToplevel(CompilerPhase.kt:33)
    at org.jetbrains.kotlin.backend.konan.KonanDriverKt.runTopLevelPhases(KonanDriver.kt:30)
    at org.jetbrains.kotlin.cli.bc.K2Native.doExecute(K2Native.kt:78)
    at org.jetbrains.kotlin.cli.bc.K2Native.doExecute(K2Native.kt:35)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:84)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:42)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:103)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:81)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:49)
    at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit(CLITool.kt:214)
    at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMain(CLITool.kt:206)
    at org.jetbrains.kotlin.cli.bc.K2Native$Companion$main$1.invoke(K2Native.kt:217)
    at org.jetbrains.kotlin.cli.bc.K2Native$Companion$main$1.invoke(K2Native.kt:208)
    at org.jetbrains.kotlin.konan.util.UtilKt.profileIf(Util.kt:39)
    at org.jetbrains.kotlin.konan.util.UtilKt.profile(Util.kt:33)
    at org.jetbrains.kotlin.cli.bc.K2Native$Companion.main(K2Native.kt:210)
    at org.jetbrains.kotlin.cli.bc.K2NativeKt.main(K2Native.kt:296)
    at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:16)


> Task :linkTestDebugExecutableIosSim FAILED

I came up with a minimal repro project (run the linkTestDebugExecutableIos task). It has something to do with creating a subclass in commonTest of a generic abstract class (or maybe even just implementing an interface) declared in commonMain, where that subclass is @Serializable. Marking the subclass's val as @Transient fixes the crash (and happened to be correct behavior-wise in my case).

KNCrashRepro.zip

bug compiler-plugin native

Most helpful comment

Getting the same issue and there is no any indication where it comes from. Just an exception:
java.lang.UnsupportedOperationException: org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl@17f0cf7

It seems the same issue calculate property:

class A(
  val modifiedAtNanos: Long = System.nanoTime()
  val syncedAtNanos: Long = 0
) {
   val requiresSync = modifiedAtNanos - syncedAtNanos > 0
}

Changing to this helped to resolve the issue:

val requiresSync: Boolean
        get() = modifiedAtNanos - syncedAtNanos > 0

All 7 comments

It seems the key part in

@Serializable
private class Subclass(val test: String): SomeAbstractClass<String>() {
    override val map: Map<String, String> = mapOf("test" to test)
}

is that map initializer depends on test val, which causes the crash, so it is similar to #133. Removing dependency may help.

I mentioned that we meant for this to be marked as @Transient in the first place, so I agree with you there: the dependency does not need to be present in the serialization. However, this did work in the previous release. At the very least, it would be great if this emitted a more useful error with a file name and line number. Debugging this was painful (had to remove all test files and re-add one at a time).

Getting the same issue and there is no any indication where it comes from. Just an exception:
java.lang.UnsupportedOperationException: org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl@17f0cf7

It seems the same issue calculate property:

class A(
  val modifiedAtNanos: Long = System.nanoTime()
  val syncedAtNanos: Long = 0
) {
   val requiresSync = modifiedAtNanos - syncedAtNanos > 0
}

Changing to this helped to resolve the issue:

val requiresSync: Boolean
        get() = modifiedAtNanos - syncedAtNanos > 0

Same issue for me on 1.3.31 compiling for iOS:

val reasons: List<Reason>? = entryReasons?.reasons

causes the same error in the compiler. Changing to:

val reasons: List<Reason>? get() = entryReasons?.reasons

fixes it. Thank you.

Not seeing this anymore. Closing

I've also faced this issue and after trying everything I made one small change and tried it one more time and that was the issues. The main problem with these cases is they are all correct and should not make any kind of issues but for some reason they do.
This is a note to myself and anyone who is still facing this issue in case anyone is still facing it. Check all the serialized classes and their variables and make sure they have are not following these wrong cases.

Extra Info
Kotlin 1.3.61
kotlinx.serialization 0.14.0

ex: wrong cases that will result in this error (As it happened in my project)
case 1

@Serializable
class LoginRequest(
    @SerialName("Email") private val email: String,
    @SerialName("Password") private val password: String
) {
    var username: String = this.email
}

case 2

@Serializable
class LoginRequest(
    @SerialName("Email") private val email: String,
    @SerialName("Password") private val password: String
) {
    @SerialName("Username")
    var username: String = email
}

case 3

@Serializable
class LoginRequest(
    @SerialName("Email") private val email: String,
    @SerialName("Password") private val password: String
) {
    @SerialName("Username")
    var username: String = this.email
}

Correct/Right case

@Serializable
data class LoginRequest(
    @SerialName("Email")
    private val email: String,
    @SerialName("Password")
    private val password: String
) {
    @SerialName("Username")
    private var username: String

    init {
        this.username = this.email
    }
}

@hamada147 can you file a new issue? If you're still experiencing something like this, it's important that the issue is properly record, so that it can be fixed.

Was this page helpful?
0 / 5 - 0 ratings