Files
kotlin-fork/compiler/testData/codegen/box/contracts/fieldInConstructorParens.kt
T
Ilmir Usmanov 3b5706972e Extract effect from lambda argument if it is in parentheses
Otherwise, contracts on the parameter have no effect.
 #KT-42044 Fixed
 #KT-26229 Fixed
2020-10-12 20:16:19 +02:00

27 lines
575 B
Kotlin
Vendored

// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// IGNORE_BACKEND: NATIVE
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
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}"
}