[FIR] Substitute types from arguments in evaluating of contract

#KT-41078
This commit is contained in:
Dmitriy Novozhilov
2021-04-16 12:41:59 +03:00
committed by TeamCityServer
parent 80f95528c2
commit 91fedd6a12
8 changed files with 149 additions and 16 deletions
@@ -0,0 +1,25 @@
// WITH_STDLIB
import kotlin.contracts.*
inline fun <reified T> requreIsInstance(value: Any) contract [
returns() implies (value is T)
] {
if (value !is T) throw IllegalArgumentException()
}
fun test_1(s: Any) {
requreIsInstance<String>(s)
s.length
}
inline fun <reified T> requreIsInstanceOf(value: Any, requiredValue: T) contract [
returns() implies (value is T)
] {
if (value !is T) throw IllegalArgumentException()
}
fun test_2(x: Any, s: String) {
requreIsInstanceOf(x, s)
x.length
}