Files
kotlin-fork/compiler/testData/codegen/box/contracts/nestedLambdaInNonInlineCallExactlyOnce.kt
T
2021-09-10 16:29:16 +03:00

28 lines
480 B
Kotlin
Vendored

// !OPT_IN: kotlin.contracts.ExperimentalContracts
// IGNORE_BACKEND: JVM
// WITH_RUNTIME
// 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"
}