Files
kotlin-fork/compiler/testData/codegen/box/nothingValue/nothingValueException.kt
T
Igor Chevdar e41b5fc1c6 [IR] Turned on a test for K/N + minor refactoring
NothingValueException has already been supported in K/N
2020-06-02 14:50:17 +05:00

28 lines
729 B
Kotlin
Vendored

// IGNORE_BACKEND: JS
fun <T> something(): T = Any() as T
class Context<T>
fun <T> Any.decodeIn(typeFrom: Context<in T>): T = something()
fun <T> Any?.decodeOut(typeFrom: Context<out T>): T {
return this?.decodeIn(typeFrom) // decodeIn result is of type Nothing
?: throw AssertionError("")
}
fun box(): String {
try {
"str".decodeOut(Context<Any>())
} catch (e: Exception) {
// TODO check FQN
val exceptionClassName = e::class.simpleName
if (exceptionClassName != "KotlinNothingValueException") {
throw AssertionError("Unexpected exception: $e")
} else {
return "OK"
}
}
throw AssertionError("Should fail with exception")
}