Files
kotlin-fork/compiler/testData/codegen/box/contracts/nestedLambdaInNonInlineCallExactlyOnce.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

28 lines
479 B
Kotlin
Vendored

// !OPT_IN: kotlin.contracts.ExperimentalContracts
// IGNORE_BACKEND: JVM
// WITH_STDLIB
// KT-38849
import kotlin.contracts.*
fun block(lambda: () -> Unit) {
contract {
callsInPlace(lambda, InvocationKind.EXACTLY_ONCE)
}
lambda()
}
fun box(): String {
val list: List<Int>
block {
list = listOf(1, 2, 3)
}
block {
if (listOf(2, 3, 4).first { list.contains(it) } != 2) throw AssertionError("Fail")
}
return "OK"
}