Add test on safecall of function with returns(null) contract

Currently with non-desired testdata, fix incoming in the next commit.
This commit is contained in:
Dmitry Savvinov
2018-09-05 14:08:48 +03:00
parent 1530a8bf53
commit 18338f4ea3
4 changed files with 32 additions and 0 deletions
@@ -0,0 +1,17 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
import kotlin.contracts.*
fun Any.nullWhenString(): Any? {
contract {
returns(null) implies (this@nullWhenString is String)
}
return if (this is String) null else this
}
fun test(x: Int?) {
if (x?.nullWhenString() == null) {
<!DEBUG_INFO_SMARTCAST!>x<!>.length
}
}
@@ -0,0 +1,5 @@
package
public fun test(/*0*/ x: kotlin.Int?): kotlin.Unit
public fun kotlin.Any.nullWhenString(): kotlin.Any?
Returns(NULL) -> <this> is String