Handle non-reified type parameters of function inside serializer<T>() intrinsic

to match an error message thrown from KType-based serializer<T>().

Fixes https://github.com/Kotlin/kotlinx.serialization/issues/2528
This commit is contained in:
Leonid Startsev
2023-12-18 19:04:30 +01:00
committed by Space Team
parent a2cd2200d6
commit 6c6f2ccacd
11 changed files with 429 additions and 18 deletions
@@ -0,0 +1,43 @@
// TARGET_BACKEND: JVM_IR
// WITH_STDLIB
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.internal.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.modules.*
import java.lang.AssertionError
import java.lang.IllegalArgumentException
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.modules.*
import kotlin.reflect.typeOf
@Serializable
class Box<T>(val t: T)
inline fun <reified T> inner() = serializer<T>()
fun <T> outer() = inner<Box<T>>()
fun checkBlock(name: String, block:() -> Unit) {
try {
block()
} catch (e: IllegalArgumentException) {
if (!e.message!!.contains("Captured type parameter T of <root>.IntrinsicsNonReifiedKt.outer from generic non-reified function.")) throw e
return
}
throw AssertionError("Expected exception to be thrown in block $name")
}
fun box(): String {
checkBlock("string") {
outer<String>()
}
checkBlock("list string") {
outer<List<String>>()
}
return "OK"
}