b29a6e48fb
- Introduce new language feature 'ReadDeserializedContracts', which allows to deserialize contracts from metadata. - Introduce new language feature 'AllowContractsForCustomFunctions', which allows reading contracts from sources. - Use new features instead of combination 'CallsInPlaceEffect || ReturnsEffect' - Rename 'CallsInPlaceEffect' -> 'UseCallsInPlaceEffect', 'ReturnsEffect' -> 'UseReturnsEffect'. As names suggest, they control if it is allowed to use corresponding effect in analysis. We have to introduce separate 'ReadDeserializedContracts' to enable contracts only in some modules of the project, because libraries are read with project-wide settings (see KT-20692).
36 lines
714 B
Kotlin
Vendored
36 lines
714 B
Kotlin
Vendored
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
|
// !WITH_NEW_INFERENCE
|
|
|
|
import kotlin.internal.contracts.*
|
|
|
|
fun Any?.isNull(): Boolean {
|
|
contract {
|
|
returns(false) implies (this@isNull != null)
|
|
}
|
|
return this == null
|
|
}
|
|
|
|
fun smartcastOnReceiver(x: Int?) {
|
|
if (x.isNull()) {
|
|
x<!UNSAFE_CALL!>.<!>inc()
|
|
}
|
|
else {
|
|
<!DEBUG_INFO_SMARTCAST!>x<!>.dec()
|
|
}
|
|
}
|
|
|
|
class UnstableReceiver {
|
|
var x: Int? = 42
|
|
|
|
fun smartcastOnUnstableReceiver() {
|
|
if (x.isNull()) {
|
|
x<!UNSAFE_CALL!>.<!>inc()
|
|
}
|
|
else {
|
|
<!SMARTCAST_IMPOSSIBLE!>x<!>.dec()
|
|
}
|
|
}
|
|
}
|
|
|