Files
kotlin-fork/compiler/testData/codegen/box/contracts/fieldInConstructorParens.kt
T
2023-12-26 10:18:19 +00:00

27 lines
546 B
Kotlin
Vendored

// !OPT_IN: kotlin.contracts.ExperimentalContracts
// WITH_STDLIB
// JVM_ABI_K1_K2_DIFF: KT-62464
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}"
}