e6b5cb5216
Update includes:
- Changing syntax of `OI/`NI` tags from `<!NI;TAG!>` to `<!TAG{NI}!>`
- Fix some incorrect directives
- Change order of diagnostics in some places
- Remove ignored diagnostics from FIR test data (previously `DIAGNOSTICS` didn't work)
- Update FIR dumps in some places and add `FIR_IDENTICAL` if needed
- Replace all JAVAC_SKIP with SKIP_JAVAC directive
58 lines
1.3 KiB
Kotlin
Vendored
58 lines
1.3 KiB
Kotlin
Vendored
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
|
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
|
// !WITH_NEW_INFERENCE
|
|
|
|
import kotlin.contracts.*
|
|
|
|
fun nullWhenNull(x: Int?): Int? {
|
|
contract {
|
|
returnsNotNull() implies (x != null)
|
|
}
|
|
return x?.inc()
|
|
}
|
|
|
|
fun testNullWhenNull(x: Int?) {
|
|
if (nullWhenNull(x) == null) {
|
|
x<!UNSAFE_CALL!>.<!>dec()
|
|
}
|
|
else {
|
|
<!DEBUG_INFO_SMARTCAST!>x<!>.dec()
|
|
}
|
|
|
|
if (nullWhenNull(x) != null) {
|
|
<!DEBUG_INFO_SMARTCAST!>x<!>.dec()
|
|
}
|
|
else {
|
|
x<!UNSAFE_CALL!>.<!>dec()
|
|
}
|
|
|
|
x<!UNSAFE_CALL!>.<!>dec()
|
|
}
|
|
|
|
// NB. it is the same function as `nullWhenNull`, but annotations specifies other facet of the function behaviour
|
|
fun notNullWhenNotNull (x: Int?): Int? {
|
|
contract {
|
|
returns(null) implies (x == null)
|
|
}
|
|
return x?.inc()
|
|
}
|
|
|
|
fun testNotNullWhenNotNull (x: Int?) {
|
|
if (notNullWhenNotNull(x) == null) {
|
|
<!SENSELESS_COMPARISON!><!DEBUG_INFO_CONSTANT!>x<!> == null<!>
|
|
}
|
|
else {
|
|
x<!UNSAFE_CALL!>.<!>dec()
|
|
}
|
|
|
|
if (notNullWhenNotNull(x) != null) {
|
|
x<!UNSAFE_CALL!>.<!>dec()
|
|
}
|
|
else {
|
|
<!SENSELESS_COMPARISON!><!DEBUG_INFO_CONSTANT!>x<!> == null<!>
|
|
}
|
|
|
|
x<!UNSAFE_CALL!>.<!>dec()
|
|
}
|