mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-11 08:31:30 +00:00
31 lines
490 B
Kotlin
Vendored
31 lines
490 B
Kotlin
Vendored
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
|
// IGNORE_BACKEND: NATIVE
|
|
|
|
// FILE: 1.kt
|
|
|
|
package test
|
|
|
|
import kotlin.contracts.*
|
|
|
|
public inline fun <R> myrun(block: () -> R): R {
|
|
contract {
|
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
|
}
|
|
return block()
|
|
}
|
|
|
|
// FILE: 2.kt
|
|
|
|
import test.*
|
|
|
|
fun cond() = true
|
|
fun test(s: String) = s
|
|
|
|
fun box(): String {
|
|
val x: String
|
|
myrun {
|
|
x = if (cond()) test("OK") else test("fail")
|
|
}
|
|
return x
|
|
}
|