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).
55 lines
1.6 KiB
Kotlin
Vendored
55 lines
1.6 KiB
Kotlin
Vendored
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
|
|
|
import kotlin.internal.contracts.*
|
|
|
|
fun safeIsString(x: Any?): Boolean? {
|
|
contract {
|
|
returns(true) implies (x is String)
|
|
}
|
|
return x?.let { it is String }
|
|
}
|
|
|
|
fun elseWithNullableResult(x: Any?) {
|
|
when (safeIsString(x)) {
|
|
false -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
else -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
}
|
|
|
|
when (safeIsString(x)) {
|
|
true -> <!DEBUG_INFO_SMARTCAST!>x<!>.length
|
|
else -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
}
|
|
|
|
when (safeIsString(x)) {
|
|
true -> <!DEBUG_INFO_SMARTCAST!>x<!>.length
|
|
false -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
else -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
}
|
|
|
|
when (safeIsString(x)) {
|
|
true -> <!DEBUG_INFO_SMARTCAST!>x<!>.length
|
|
null -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
else -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
}
|
|
}
|
|
|
|
fun exhaustiveWithNullableResult(x: Any?) {
|
|
when (safeIsString(x)) {
|
|
true -> <!DEBUG_INFO_SMARTCAST!>x<!>.length
|
|
false -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
null -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
}
|
|
|
|
when (safeIsString(x)) {
|
|
false -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
true -> <!DEBUG_INFO_SMARTCAST!>x<!>.length
|
|
null -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
}
|
|
|
|
when (safeIsString(x)) {
|
|
false -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
null -> x.<!UNRESOLVED_REFERENCE!>length<!>
|
|
true -> <!DEBUG_INFO_SMARTCAST!>x<!>.length
|
|
}
|
|
} |