[FIR] Add ReturnsImplies effect analyzer
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
import kotlin.contracts.*
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
fun foo(x: String?): Any? {
|
||||
<!WRONG_IMPLIES_CONDITION!>contract {
|
||||
returns(null) implies (x != null)
|
||||
}<!>
|
||||
|
||||
if (true) {
|
||||
throw java.lang.IllegalArgumentException()
|
||||
}
|
||||
|
||||
return x
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
fun bar(x: String?): Any? {
|
||||
<!WRONG_IMPLIES_CONDITION!>contract {
|
||||
returns() implies (x != null)
|
||||
}<!>
|
||||
|
||||
if (x == null) {
|
||||
return x
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
fun baz(x: String?): Any? {
|
||||
<!WRONG_IMPLIES_CONDITION!>contract {
|
||||
returns(null) implies (x != null)
|
||||
}<!>
|
||||
|
||||
return x
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
FILE: notNull.kt
|
||||
@R|kotlin/OptIn|(vararg(<getClass>(Q|kotlin/contracts/ExperimentalContracts|))) public final fun foo(x: R|kotlin/String?|): R|kotlin/Any?|
|
||||
[R|Contract description]
|
||||
<
|
||||
Returns(NULL) -> x != null
|
||||
>
|
||||
{
|
||||
[StubStatement]
|
||||
when () {
|
||||
Boolean(true) -> {
|
||||
throw Q|java/lang|.R|java/lang/IllegalArgumentException.IllegalArgumentException|()
|
||||
}
|
||||
}
|
||||
|
||||
^foo R|<local>/x|
|
||||
}
|
||||
@R|kotlin/OptIn|(vararg(<getClass>(Q|kotlin/contracts/ExperimentalContracts|))) public final fun bar(x: R|kotlin/String?|): R|kotlin/Any?|
|
||||
[R|Contract description]
|
||||
<
|
||||
Returns(WILDCARD) -> x != null
|
||||
>
|
||||
{
|
||||
[StubStatement]
|
||||
when () {
|
||||
==(R|<local>/x|, Null(null)) -> {
|
||||
^bar R|<local>/x|
|
||||
}
|
||||
}
|
||||
|
||||
^bar R|<local>/x|
|
||||
}
|
||||
@R|kotlin/OptIn|(vararg(<getClass>(Q|kotlin/contracts/ExperimentalContracts|))) public final fun baz(x: R|kotlin/String?|): R|kotlin/Any?|
|
||||
[R|Contract description]
|
||||
<
|
||||
Returns(NULL) -> x != null
|
||||
>
|
||||
{
|
||||
[StubStatement]
|
||||
^baz R|<local>/x|
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import kotlin.contracts.*
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
fun Any?.isNotNull(): Boolean {
|
||||
contract {
|
||||
returns(true) implies (this@isNotNull != null)
|
||||
}
|
||||
return this != null
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
val Any?.isNotNull: Boolean
|
||||
get() {
|
||||
<!WRONG_IMPLIES_CONDITION!>contract {
|
||||
returns(true) implies (this@isNotNull != null)
|
||||
}<!>
|
||||
return this@isNotNull != null
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
FILE: propertyGetter.kt
|
||||
@R|kotlin/OptIn|(vararg(<getClass>(Q|kotlin/contracts/ExperimentalContracts|))) public final fun R|kotlin/Any?|.isNotNull(): R|kotlin/Boolean|
|
||||
[R|Contract description]
|
||||
<
|
||||
Returns(TRUE) -> this != null
|
||||
>
|
||||
{
|
||||
[StubStatement]
|
||||
^isNotNull !=(this@R|/isNotNull|, Null(null))
|
||||
}
|
||||
@R|kotlin/OptIn|(vararg(<getClass>(Q|kotlin/contracts/ExperimentalContracts|))) public final val R|kotlin/Any?|.isNotNull: R|kotlin/Boolean|
|
||||
public get(): R|kotlin/Boolean|
|
||||
[R|Contract description]
|
||||
<
|
||||
Returns(TRUE) -> this != null
|
||||
>
|
||||
{
|
||||
[StubStatement]
|
||||
^ !=(this@R|/isNotNull|, Null(null))
|
||||
}
|
||||
Reference in New Issue
Block a user