mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-12 00:21:32 +00:00
In general case parameter type could differ from actual default lambda type.
E.g.: fun inlineFun(s: (Child) -> Base = { a: Base -> a as Child}),
where type of default lambda is '(Base) -> Child'.
In such case we should find somehow actual invoke method in bytecode knowing
only name, number of parameters and that's actual invoke is non-synthetic
regardless of bridge one.
#KT-21946 Fixed
25 lines
639 B
Kotlin
Vendored
25 lines
639 B
Kotlin
Vendored
// TARGET_BACKEND: JVM
|
|
// IGNORE_BACKEND: JVM_IR
|
|
// WITH_RUNTIME
|
|
// FILE: 1.kt
|
|
// SKIP_INLINE_CHECK_IN: enumOrThrow$default
|
|
package test
|
|
|
|
enum class TarEnum {
|
|
OK
|
|
}
|
|
inline fun <reified T : Enum<T>> String?.enumOrNull(): T? {
|
|
this ?: return null
|
|
return enumValues<T>().firstOrNull { it.name == this }
|
|
}
|
|
|
|
inline fun <reified T : Enum<T>> String?.enumOrThrow(handleNull: () -> Throwable = { IllegalArgumentException("Enum type ${T::class.java} not contain value=$this") }): T {
|
|
return this.enumOrNull<T>() ?: throw handleNull()
|
|
}
|
|
|
|
// FILE: 2.kt
|
|
import test.*
|
|
|
|
fun box(): String {
|
|
return "OK".enumOrThrow<TarEnum>()!!.name
|
|
} |