Files
kotlin-fork/compiler/testData/codegen/box/contracts/constructorArgument.kt
T
2020-03-04 16:55:33 +03:00

27 lines
443 B
Kotlin
Vendored

// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// 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
}