Files
kotlin-fork/compiler/testData/cfgVariablesWithStdLib/contracts/breakContinuesInInlinedLambda.kt
T
Dmitry Savvinov ee8702d21e Load of testdata change due to contracts publishing
See changes in e2606b72bdbec2fea567d4127197707869eb801e
2018-08-30 16:19:55 +03:00

44 lines
962 B
Kotlin
Vendored

// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.internal.ContractsDsl
import kotlin.contracts.*
inline fun <T> myRun(block: () -> T): T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun getBoolean(): Boolean = false
fun test() {
val x: Int
if (getBoolean())
myRun {
while (getBoolean()) {
do {
myRun {
if (getBoolean()) {
x = 42
}
else {
x = 43
}
}
break
} while (getBoolean())
myRun { x.inc() }
myRun { x = 42 }
break
}
x = 42
}
else
myRun {
x = 42
}
x.inc()
}