[FIR] Add contracts resolve for property accessors

This commit is contained in:
Dmitriy Novozhilov
2020-04-13 10:55:29 +03:00
parent d808f3e4fb
commit 1074e4bf29
4 changed files with 119 additions and 2 deletions
@@ -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<!>()
}
@@ -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]>#()
}