[FIR] KT-56877: Allow referencing implicit receivers in class contracts

This commit is contained in:
Nikolay Lunyak
2023-03-07 13:27:44 +02:00
committed by Space Team
parent 409249267c
commit c7a71fec17
10 changed files with 20 additions and 67 deletions
@@ -1,42 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
package my
// Accepts block, can't be distinguished from kotlin.contract without resolve
fun contract(block: () -> Unit) {}
// Accepts int, potentially can be distinguished from kotlin.contract by PSI,
// but as of Kotlin 1.3.0, we don't do that
fun contract(i: Int) {}
fun doStuff() {}
class SomeClass {
fun contract() {}
fun callMemberContractWithThis() {
this.contract()
}
fun callMemberContractWithoutThis() {
<!NONE_APPLICABLE!>contract<!>()
}
fun callTopLevelSamePsiInMember() {
contract { }
}
}
fun callTopLevelSamePsi() {
contract { }
}
fun callTopLevelDifferentPsi() {
contract(42)
}
fun callTopLevelSamePsiNotFirstStatement() {
doStuff()
contract { }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
package my
@@ -10,13 +10,13 @@ class Foo {
inner class Bar {
fun good() {
contract {
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (this<!UNRESOLVED_LABEL!>@Bar<!> != null)<!>
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (this@Bar != null)<!>
}
}
fun badOuter() {
contract {
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (this<!UNRESOLVED_LABEL!>@Foo<!> != null)<!>
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (this@Foo != null)<!>
}
}
@@ -34,7 +34,7 @@ class Foo {
fun A?.badWithReceiver() {
contract {
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (this<!UNRESOLVED_LABEL!>@Bar<!> != null)<!>
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (this@Bar != null)<!>
}
}
}
@@ -7,7 +7,7 @@ import kotlin.contracts.*
class Foo(val x: Int?) {
fun isXNull(): Boolean {
contract {
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(false) implies (<!UNRESOLVED_REFERENCE!>x<!> != null)<!>
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(false) implies (x != null)<!>
}
return x != null
}
@@ -7,8 +7,8 @@ import kotlin.contracts.*
class Foo(val x: Int?) {
fun isXNull(): Boolean {
contract {
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(false) implies (<!UNRESOLVED_REFERENCE!>x<!> != null)<!>
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(false) implies (x != null)<!>
}
return x != null
}
}
}