Files
kotlin-fork/compiler/testData/codegen/box/contracts/fieldReadInConstructor.kt
T
Roman Artemev 686e5e7f2b [TEST] Fix test data.
Due to JS IR runner doesn't override stdout test fails.
Remove using stdout from test.
2021-10-11 21:19:28 +03:00

32 lines
486 B
Kotlin
Vendored

// !OPT_IN: kotlin.contracts.ExperimentalContracts
// IGNORE_BACKEND: NATIVE
// WITH_RUNTIME
import kotlin.contracts.*
var x = ""
fun baz(s: String) { x += s }
class A {
val value = "Some value"
init {
foo {
baz(value)
}
}
}
fun foo(block: () -> Unit) {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
block()
}
fun box(): String {
val a = A()
if (x != a.value) return "FAIL: $x"
return "OK"
}