Files
kotlin-fork/compiler/testData/codegen/box/contracts/fieldInConstructorParens.kt
T
2022-08-01 08:57:16 +00:00

25 lines
513 B
Kotlin
Vendored

// !OPT_IN: kotlin.contracts.ExperimentalContracts
// WITH_STDLIB
import kotlin.contracts.*
class Smth {
val whatever: Int
init {
calculate({ whatever = it })
}
@OptIn(ExperimentalContracts::class)
private inline fun calculate(block: (Int) -> Unit) {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
block(42)
}
}
fun box(): String {
val smth = Smth()
return if (smth.whatever == 42) "OK" else "FAIL ${smth.whatever}"
}