Files
kotlin-fork/plugins/kotlinx-serialization/testData/boxIr/intrinsicsNonReified.kt
T
2023-12-20 13:50:39 +00:00

44 lines
1.1 KiB
Kotlin
Vendored

// 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"
}