Fix compilation error when @Serializable expect class has explicit companion

as it may have no primary constructor (only actual class has it).

Refactor & rename Fir2IrGeneratorUtils.kt as having 'Fir' in stacktrace
when actual K2 compiler is not used is very confusing.

Fixes https://github.com/Kotlin/kotlinx.serialization/issues/2134
#KT-55683 Fixed
This commit is contained in:
Leonid Startsev
2022-12-21 18:13:11 +01:00
committed by Space Team
parent 6d3812c259
commit 2634303055
7 changed files with 56 additions and 9 deletions
@@ -0,0 +1,35 @@
// IGNORE_BACKEND_K2: JVM_IR
// TARGET_BACKEND: JVM_IR
// !LANGUAGE: +MultiPlatformProjects
// WITH_STDLIB
// FILE: common.kt
package foo
import kotlinx.serialization.*
@Serializable
expect class Expected {
companion object { fun factoryMethod(): Expected }
}
// FILE: jvm.kt
package foo
import kotlinx.serialization.*
@Serializable
actual class Expected {
actual companion object { actual fun factoryMethod(): Expected = Expected() }
}
fun box(): String {
val b = Expected.factoryMethod()
if (b !is Expected) return "Incorrect factory method"
val desc = Expected.serializer().descriptor
if (desc.toString() != "foo.Expected()") return "Incorrect descriptor $desc"
return "OK"
}