Backend Internal error compiling serilizable class

Hi,

I have a reproducible test case of js and jvm compiler failure when trying to compile serializable class with a custom serializer.

Any help appreciated.

The error is shown below followed by the main class and the gradle build file.

Error:

> Task :compileKotlin FAILED
e: java.lang.IllegalStateException: Backend Internal error: Exception during code generation
Cause: Back-end (JVM) Internal error: wrong code generated
org.jetbrains.kotlin.codegen.CompilationException Back-end (JVM) Internal error: Couldn't transform method node:
<init> (ILjava/lang/String;Lcom/soywiz/klock/DateTime;Lkotlinx/serialization/SerializationConstructorMarker;)V:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someValue"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ALOAD 2
    PUTFIELD MyTestClass.someValue : Ljava/lang/String;
    ILOAD 1
    ICONST_2
    IAND
    ICONST_0
    IF_ICMPNE L2
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someDate"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L2
    ALOAD 0
    DLOAD 3
    PUTFIELD MyTestClass.someDate : D
    RETURN
   L3
    LOCALVARIABLE this LMyTestClass; L0 L3 0
    LOCALVARIABLE seen1 I L0 L3 1
    LOCALVARIABLE someValue Ljava/lang/String; L0 L3 2
    LOCALVARIABLE someDate Lcom/soywiz/klock/DateTime; L0 L3 3
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L3 4
    MAXSTACK = 3
    MAXLOCALS = 5

Cause: AFTER mandatory stack transformations: incorrect bytecode
Element is unknownThe root cause was thrown at: MethodVerifier.kt:28
bytecode:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someValue"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ALOAD 2
    PUTFIELD MyTestClass.someValue : Ljava/lang/String;
    ILOAD 1
    ICONST_2
    IAND
    ICONST_0
    IF_ICMPNE L2
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someDate"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L2
    ALOAD 0
    DLOAD 3
    PUTFIELD MyTestClass.someDate : D
    RETURN
   L3
    LOCALVARIABLE this LMyTestClass; L0 L3 0
    LOCALVARIABLE seen1 I L0 L3 1
    LOCALVARIABLE someValue Ljava/lang/String; L0 L3 2
    LOCALVARIABLE someDate Lcom/soywiz/klock/DateTime; L0 L3 3
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L3 4
    MAXSTACK = 3
    MAXLOCALS = 5

Cause: Back-end (JVM) Internal error: Couldn't transform method node:
<init> (ILjava/lang/String;Lcom/soywiz/klock/DateTime;Lkotlinx/serialization/SerializationConstructorMarker;)V:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someValue"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ALOAD 2
    PUTFIELD MyTestClass.someValue : Ljava/lang/String;
    ILOAD 1
    ICONST_2
    IAND
    ICONST_0
    IF_ICMPNE L2
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someDate"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L2
    ALOAD 0
    DLOAD 3
    PUTFIELD MyTestClass.someDate : D
    RETURN
   L3
    LOCALVARIABLE this LMyTestClass; L0 L3 0
    LOCALVARIABLE seen1 I L0 L3 1
    LOCALVARIABLE someValue Ljava/lang/String; L0 L3 2
    LOCALVARIABLE someDate Lcom/soywiz/klock/DateTime; L0 L3 3
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L3 4
    MAXSTACK = 3
    MAXLOCALS = 5

Cause: AFTER mandatory stack transformations: incorrect bytecode
Element is unknownThe root cause was thrown at: MethodVerifier.kt:28
File being compiled at position: (10,1) in /home/colin/Desktop/Temp/test-klock-serialization/src/main/java/Main.kt
The root cause was thrown at: TransformationMethodVisitor.kt:92
File being compiled at position: file:///home/colin/Desktop/Temp/test-klock-serialization/src/main/java/Main.kt
The root cause was thrown at: FunctionCodegen.java:995
	at org.jetbrains.kotlin.codegen.CompilationErrorHandler.lambda$static$0(CompilationErrorHandler.java:24)
	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:76)
	at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generatePackage(CodegenFactory.kt:96)
	at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generateModule(CodegenFactory.kt:67)
	at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.doGenerateFiles(KotlinCodegenFacade.java:47)
	at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:39)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:476)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:164)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:166)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:56)
	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:104)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:349)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:105)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:237)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:37)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:79)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:91)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.execIncrementalCompiler(CompileServiceImpl.kt:579)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execIncrementalCompiler(CompileServiceImpl.kt:102)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:455)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:102)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:1005)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:102)
	at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:138)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1047)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1004)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:454)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
	at sun.rmi.transport.Transport$1.run(Transport.java:200)
	at sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: wrong code generated
org.jetbrains.kotlin.codegen.CompilationException Back-end (JVM) Internal error: Couldn't transform method node:
<init> (ILjava/lang/String;Lcom/soywiz/klock/DateTime;Lkotlinx/serialization/SerializationConstructorMarker;)V:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someValue"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ALOAD 2
    PUTFIELD MyTestClass.someValue : Ljava/lang/String;
    ILOAD 1
    ICONST_2
    IAND
    ICONST_0
    IF_ICMPNE L2
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someDate"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L2
    ALOAD 0
    DLOAD 3
    PUTFIELD MyTestClass.someDate : D
    RETURN
   L3
    LOCALVARIABLE this LMyTestClass; L0 L3 0
    LOCALVARIABLE seen1 I L0 L3 1
    LOCALVARIABLE someValue Ljava/lang/String; L0 L3 2
    LOCALVARIABLE someDate Lcom/soywiz/klock/DateTime; L0 L3 3
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L3 4
    MAXSTACK = 3
    MAXLOCALS = 5

Cause: AFTER mandatory stack transformations: incorrect bytecode
Element is unknownThe root cause was thrown at: MethodVerifier.kt:28
bytecode:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someValue"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ALOAD 2
    PUTFIELD MyTestClass.someValue : Ljava/lang/String;
    ILOAD 1
    ICONST_2
    IAND
    ICONST_0
    IF_ICMPNE L2
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someDate"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L2
    ALOAD 0
    DLOAD 3
    PUTFIELD MyTestClass.someDate : D
    RETURN
   L3
    LOCALVARIABLE this LMyTestClass; L0 L3 0
    LOCALVARIABLE seen1 I L0 L3 1
    LOCALVARIABLE someValue Ljava/lang/String; L0 L3 2
    LOCALVARIABLE someDate Lcom/soywiz/klock/DateTime; L0 L3 3
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L3 4
    MAXSTACK = 3
    MAXLOCALS = 5

Cause: Back-end (JVM) Internal error: Couldn't transform method node:
<init> (ILjava/lang/String;Lcom/soywiz/klock/DateTime;Lkotlinx/serialization/SerializationConstructorMarker;)V:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someValue"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ALOAD 2
    PUTFIELD MyTestClass.someValue : Ljava/lang/String;
    ILOAD 1
    ICONST_2
    IAND
    ICONST_0
    IF_ICMPNE L2
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someDate"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L2
    ALOAD 0
    DLOAD 3
    PUTFIELD MyTestClass.someDate : D
    RETURN
   L3
    LOCALVARIABLE this LMyTestClass; L0 L3 0
    LOCALVARIABLE seen1 I L0 L3 1
    LOCALVARIABLE someValue Ljava/lang/String; L0 L3 2
    LOCALVARIABLE someDate Lcom/soywiz/klock/DateTime; L0 L3 3
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L3 4
    MAXSTACK = 3
    MAXLOCALS = 5

Cause: AFTER mandatory stack transformations: incorrect bytecode
Element is unknownThe root cause was thrown at: MethodVerifier.kt:28
File being compiled at position: (10,1) in /home/colin/Desktop/Temp/test-klock-serialization/src/main/java/Main.kt
The root cause was thrown at: TransformationMethodVisitor.kt:92
	at org.jetbrains.kotlin.codegen.FunctionCodegen.endVisit(FunctionCodegen.java:995)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:487)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:260)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:176)
	at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.JVMCodegenUtilKt.generateMethod(JVMCodegenUtil.kt:150)
	at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializableCodegenImpl.generateInternalConstructor(SerializableCodegenImpl.kt:80)
	at org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializableCodegen.generateSyntheticInternalConstructor(SerializableCodegen.kt:41)
	at org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializableCodegen.generate(SerializableCodegen.kt:33)
	at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializableCodegenImpl$Companion.generateSerializableExtensions(SerializableCodegenImpl.kt:47)
	at org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationCodegenExtension.generateClassSyntheticParts(SerializationCodegenExtension.kt:29)
	at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen.generateSyntheticPartsAfterBody(ImplementationBodyCodegen.java:438)
	at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:132)
	at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:302)
	at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:286)
	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateClassesAndObjectsInFile(PackageCodegenImpl.java:118)
	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateFile(PackageCodegenImpl.java:137)
	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:68)
	... 44 more
Caused by: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't transform method node:
<init> (ILjava/lang/String;Lcom/soywiz/klock/DateTime;Lkotlinx/serialization/SerializationConstructorMarker;)V:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someValue"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ALOAD 2
    PUTFIELD MyTestClass.someValue : Ljava/lang/String;
    ILOAD 1
    ICONST_2
    IAND
    ICONST_0
    IF_ICMPNE L2
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "someDate"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L2
    ALOAD 0
    DLOAD 3
    PUTFIELD MyTestClass.someDate : D
    RETURN
   L3
    LOCALVARIABLE this LMyTestClass; L0 L3 0
    LOCALVARIABLE seen1 I L0 L3 1
    LOCALVARIABLE someValue Ljava/lang/String; L0 L3 2
    LOCALVARIABLE someDate Lcom/soywiz/klock/DateTime; L0 L3 3
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L3 4
    MAXSTACK = 3
    MAXLOCALS = 5

Cause: AFTER mandatory stack transformations: incorrect bytecode
Element is unknownThe root cause was thrown at: MethodVerifier.kt:28
	at org.jetbrains.kotlin.codegen.TransformationMethodVisitor.visitEnd(TransformationMethodVisitor.kt:92)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.endVisit(FunctionCodegen.java:983)
	... 60 more
Caused by: java.lang.AssertionError: AFTER mandatory stack transformations: incorrect bytecode
	at org.jetbrains.kotlin.codegen.optimization.MethodVerifier.transform(MethodVerifier.kt:28)
	at org.jetbrains.kotlin.codegen.optimization.transformer.CompositeMethodTransformer.transform(CompositeMethodTransformer.kt:25)
	at org.jetbrains.kotlin.codegen.optimization.OptimizationMethodVisitor.performTransformations(OptimizationMethodVisitor.kt:62)
	at org.jetbrains.kotlin.codegen.TransformationMethodVisitor.visitEnd(TransformationMethodVisitor.kt:70)
	... 61 more
Caused by: java.lang.RuntimeException: org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 31: Expected D, but found R
	at org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.runAnalyzer(MethodTransformer.java:34)
	at org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.analyze(MethodTransformer.java:44)
	at org.jetbrains.kotlin.codegen.optimization.MethodVerifier.transform(MethodVerifier.kt:26)
	... 64 more
Caused by: org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 31: Expected D, but found R
	at org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer.analyze(Analyzer.java:291)
	at org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.runAnalyzer(MethodTransformer.java:31)
	... 66 more
Caused by: org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException: Expected D, but found R
	at org.jetbrains.org.objectweb.asm.tree.analysis.BasicVerifier.copyOperation(BasicVerifier.java:102)
	at org.jetbrains.org.objectweb.asm.tree.analysis.BasicVerifier.copyOperation(BasicVerifier.java:43)
	at org.jetbrains.org.objectweb.asm.tree.analysis.Frame.execute(Frame.java:288)
	at org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer.analyze(Analyzer.java:187)
	... 67 more


Execution failed for task ':compileKotlin'.
> Internal compiler error. See log for more details


e: java.lang.IllegalStateException: Backend Internal error: Exception during code generation

The main file looks like this:

import com.soywiz.klock.DateTime
import kotlinx.serialization.*
import kotlinx.serialization.internal.DoubleDescriptor

fun main() {
    val dateTime = MyTestClass("test", DateTime.now())
}

@Serializable
data class MyTestClass(
    val someValue: String,

    @Serializable(with = DateTimeSerializer::class)
//    @ContextualSerialization
    val someDate: DateTime
)

@Serializer(forClass = DateTime::class)
object DateTimeSerializer: KSerializer<DateTime> {
    override fun serialize(encoder: Encoder, obj: DateTime) {
        encoder.encodeDouble(obj.unixMillis)
    }

    override fun deserialize(decoder: Decoder): DateTime {
        return DateTime(decoder.decodeDouble())
    }

    override val descriptor: SerialDescriptor =
        DoubleDescriptor.withName("DateTime")
}

build.gradle.kts file looks like this:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
    var kotlinVersion: String by extra
    kotlinVersion = "1.3.41" // Also see plugin below for same version

    repositories {
        mavenLocal()
    }

    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
    }
}

plugins {
    java
    kotlin("jvm") version "1.3.41"

}

apply {
    plugin("kotlinx-serialization")
}

group = "com.ccfraser.testing"
version = "1.0-SNAPSHOT"

repositories {
    jcenter()
    maven("https://dl.bintray.com/soywiz/soywiz")
}

dependencies {
    val kotlinxSerializationVersion = "0.11.1"
    val klockVersion = "1.4.0"

    implementation(kotlin("stdlib-jdk8"))
    implementation("com.soywiz:klock-metadata:$klockVersion")
    implementation("com.soywiz:klock-jvm:$klockVersion")

    implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlinxSerializationVersion")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlinxSerializationVersion")
}

configure<JavaPluginConvention> {
    sourceCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "1.8"
}

You should create an issue here: http://kotl.in/issue
Maybe check if it already exists first

Thanks, went and looked there and found the issue that seems the same (issue)

Looks like a known problem when serializing inline classes which the DateTime is.