[FIR] Add contracts resolve for property accessors
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
import kotlin.contracts.*
|
||||
|
||||
interface A {
|
||||
fun foo()
|
||||
}
|
||||
|
||||
var Any?.isNotNull: Boolean
|
||||
get() {
|
||||
contract {
|
||||
returns(true) implies (this@isNotNull != null)
|
||||
}
|
||||
return this != null
|
||||
}
|
||||
set(value) {
|
||||
contract {
|
||||
returns() implies (this@isNotNull != null)
|
||||
require(this != null)
|
||||
}
|
||||
}
|
||||
|
||||
fun test_1(a: A?) {
|
||||
if (a.isNotNull) {
|
||||
a.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||
}
|
||||
}
|
||||
|
||||
fun test_2(a: A?) {
|
||||
a.isNotNull = true
|
||||
a.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
FILE: propertyAccessors.kt
|
||||
public abstract interface A : R|kotlin/Any| {
|
||||
public abstract fun foo(): R|kotlin/Unit|
|
||||
|
||||
}
|
||||
public final var 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))
|
||||
}
|
||||
public set(value: R|kotlin/Boolean|): R|kotlin/Unit|
|
||||
[R|Contract description]
|
||||
<
|
||||
Returns(WILDCARD) -> this != null
|
||||
>
|
||||
{
|
||||
[StubStatement]
|
||||
}
|
||||
public final fun test_1(a: R|A?|): R|kotlin/Unit| {
|
||||
when () {
|
||||
R|<local>/a|.R|/isNotNull| -> {
|
||||
R|<local>/a|.<Inapplicable(WRONG_RECEIVER): [/A.foo]>#()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public final fun test_2(a: R|A?|): R|kotlin/Unit| {
|
||||
R|<local>/a|.R|/isNotNull| = Boolean(true)
|
||||
R|<local>/a|.<Inapplicable(WRONG_RECEIVER): [/A.foo]>#()
|
||||
}
|
||||
Reference in New Issue
Block a user