mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-16 15:53:55 +00:00
27 lines
628 B
Kotlin
Vendored
27 lines
628 B
Kotlin
Vendored
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +ReadDeserializedContracts
|
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
|
// IGNORE_BACKEND: JVM_IR
|
|
// IGNORE_BACKEND: NATIVE
|
|
// FILE: 1.kt
|
|
package test
|
|
|
|
import kotlin.contracts.*
|
|
|
|
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
|
public inline fun <R> myrun(block: () -> R): R {
|
|
contract {
|
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
|
}
|
|
return block()
|
|
}
|
|
|
|
// FILE: 2.kt
|
|
import test.*
|
|
|
|
fun box(): String {
|
|
val x: Long
|
|
myrun {
|
|
x = 42L
|
|
}
|
|
return if (x.inc() == 43L) "OK" else "Fail: ${x.inc()}"
|
|
} |