[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
@@ -1,3 +1,4 @@
// LANGUAGE: +ContractSyntaxV2
// SKIP_JAVAC
// This directive is needed to skip this test in LazyBodyIsNotTouchedTilContractsPhaseTestGenerated,
// because it fails to parse module structure of multimodule test
@@ -1,3 +1,4 @@
// LANGUAGE: +ContractSyntaxV2
// SKIP_JAVAC
// This directive is needed to skip this test in LazyBodyIsNotTouchedTilContractsPhaseTestGenerated,
// because it fails to parse module structure of multimodule test
@@ -0,0 +1,34 @@
FILE: disabledFeature.kt
public final inline fun <reified T> requreIsInstance(value: R|kotlin/Any|): R|kotlin/Unit|
[R|Contract description]
<
Returns(WILDCARD) -> value is T
>
{
when () {
(R|<local>/value| !is R|T|) -> {
throw R|java/lang/IllegalArgumentException.IllegalArgumentException|()
}
}
}
public final val R|kotlin/Any?|.myLength: R|kotlin/Int?|
public get(): R|kotlin/Int?|
[R|Contract description]
<
>
{
^ (this@R|/myLength| as? R|kotlin/String|)?.{ $subj$.R|kotlin/String.length| }
}
public final fun test_1(x: R|kotlin/Any|): R|kotlin/Unit| {
R|/requreIsInstance|<R|kotlin/String|>(R|<local>/x|)
R|<local>/x|.R|kotlin/String.length|
}
public final fun test_2(x: R|kotlin/Any|): R|kotlin/Unit| {
when () {
!=(R|<local>/x|.R|/myLength|, Null(null)) -> {
R|<local>/x|.<Unresolved name: length>#
}
}
}
@@ -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<!>
}
}
@@ -1,3 +1,4 @@
// LANGUAGE: +ContractSyntaxV2
// WITH_STDLIB
import kotlin.contracts.*
@@ -1,3 +1,4 @@
// LANGUAGE: +ContractSyntaxV2
import kotlin.contracts.*
fun test1(arg: Any?) contract [
@@ -19,4 +20,4 @@ fun test3(arg: Any?): Boolean contract [
] {
require(arg != null)
return true
}
}