Files
kotlin/compiler/testData/codegen/box/contracts/constructorArgument.kt
2019-11-19 11:00:09 +03:00

28 lines
473 B
Kotlin
Vendored

// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: NATIVE
import kotlin.contracts.*
fun runOnce(action: () -> Unit) {
contract {
callsInPlace(action, InvocationKind.EXACTLY_ONCE)
}
action()
}
class Foo(foo: Boolean) {
var res = "FAIL"
init {
runOnce {
foo
res = "OK"
}
}
}
fun box(): String {
val foo = Foo(true)
return foo.res
}