Insert a runtime exception if star-projection type is encountered in serializer<T>() intrinsic
This makes behavior consistent with non-intrinsified version of this function and serializer(KType). #KT-54878 Fixed
This commit is contained in:
committed by
Space Team
parent
de5fd767d4
commit
715a730819
@@ -0,0 +1,51 @@
|
||||
// IGNORE_BACKEND_K2: JVM_IR
|
||||
// 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
|
||||
|
||||
interface I
|
||||
|
||||
@Serializable
|
||||
data class Box<T: I>(val boxed: T)
|
||||
|
||||
inline fun <reified T: Any> getSer(): KSerializer<T> {
|
||||
return serializer<T>()
|
||||
}
|
||||
|
||||
inline fun <reified T: Any> getListSer(): KSerializer<List<T>> {
|
||||
return serializer<List<T>>()
|
||||
}
|
||||
|
||||
fun checkBlock(name: String, block:() -> Unit) {
|
||||
try {
|
||||
block()
|
||||
} catch (e: IllegalArgumentException) {
|
||||
if (!e.message!!.contains("Star projections in type arguments are not allowed")) throw e
|
||||
return
|
||||
}
|
||||
throw AssertionError("Expected exception to be thrown in block $name")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
checkBlock("direct") {
|
||||
serializer<Box<*>>()
|
||||
}
|
||||
checkBlock("direct list") {
|
||||
serializer<List<Box<*>>>()
|
||||
}
|
||||
checkBlock("getSer") {
|
||||
getSer<Box<*>>()
|
||||
}
|
||||
checkBlock("getListSer") {
|
||||
getListSer<Box<*>>()
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user