Files
kotlin-fork/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/require.kt
T
Dmitry Savvinov d4d7946e6a Effects: add diagnostic tests on functions from stdlib
==========
Introduction of EffectSystem: 18/18
2017-10-12 11:55:26 +03:00

27 lines
704 B
Kotlin
Vendored

// !LANGUAGE: +ReturnsEffect
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
fun testRequireSmartcast(x: Any?) {
require(x is String)
<!DEBUG_INFO_SMARTCAST!>x<!>.length
}
fun testRequireUnreachableCode() {
require(false)
println("Can't get here!")
}
fun testRequireWithMessage(x: Any?) {
require(x is String) { "x is not String!" }
<!DEBUG_INFO_SMARTCAST!>x<!>.length
}
fun testRequireWithFailingMessage(x: Any?) {
require(x is String) { throw kotlin.IllegalStateException("What a strange idea") }
<!DEBUG_INFO_SMARTCAST!>x<!>.length
}
fun tesRequireNotNullWithMessage(x: Int?) {
requireNotNull(x) { "x is null!"}
<!DEBUG_INFO_SMARTCAST!>x<!>.inc()
}