[FIR] Put new contract syntax under feauture flag

^KT-55171 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-01-23 18:05:13 +02:00
committed by Space Team
parent 2783aa13f5
commit 4c96495eef
22 changed files with 147 additions and 10 deletions
@@ -0,0 +1,26 @@
// LANGUAGE: -ContractSyntaxV2
// WITH_STDLIB
import kotlin.contracts.*
inline fun <reified T> requreIsInstance(value: Any) contract <!UNSUPPORTED_FEATURE!>[
returns() implies (value is T)
]<!> {
if (value !is T) throw IllegalArgumentException()
}
val Any?.myLength: Int?
get() contract <!UNSUPPORTED_FEATURE!>[
<!ERROR_IN_CONTRACT_DESCRIPTION!>returnsNotNull() implies (this@length is String)<!>
]<!> = (this as? String)?.length
fun test_1(x: Any) {
requreIsInstance<String>(x)
x.length
}
fun test_2(x: Any) {
if (x.myLength != null) {
x.<!UNRESOLVED_REFERENCE!>length<!>
}
}