mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-10 15:53:46 +00:00
24 lines
645 B
Kotlin
Vendored
24 lines
645 B
Kotlin
Vendored
// !LANGUAGE: +AllowContractsForCustomFunctions +ReadDeserializedContracts +AllowContractsForNonOverridableMembers +AllowReifiedGenericsInContracts
|
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
|
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
|
|
|
package test
|
|
|
|
import kotlin.contracts.*
|
|
|
|
inline fun <reified T> requireIsInstance(value: Any?) {
|
|
contract {
|
|
returns() implies (value is T)
|
|
}
|
|
if (value !is T) {
|
|
throw IllegalArgumentException()
|
|
}
|
|
}
|
|
|
|
inline fun <reified T, reified U> cast(value: Any?, z: U): T {
|
|
contract {
|
|
returns() implies (value is T)
|
|
}
|
|
return value as T
|
|
}
|