mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
- Add ContractDescriptorRenderer - Add option to dump function contracts in DescriptorRendererOptions - Add parsing of LANGUAGE_VERSION directive in AbstractLoadJava - Add tests on serialization-deserializaton identity of contracts ========== Introduction of EffectSystem: 13/18
65 lines
1.4 KiB
Kotlin
Vendored
65 lines
1.4 KiB
Kotlin
Vendored
// LANGUAGE_VERSION: 1.3
|
|
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
|
|
|
package test
|
|
|
|
import kotlin.internal.contracts.*
|
|
|
|
public inline fun <R> run(block: () -> R): R {
|
|
contract {
|
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
|
}
|
|
return block()
|
|
}
|
|
|
|
public inline fun <T, R> T.run(block: T.() -> R): R {
|
|
contract {
|
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
|
}
|
|
return block()
|
|
}
|
|
|
|
public inline fun <T, R> with(receiver: T, block: T.() -> R): R {
|
|
contract {
|
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
|
}
|
|
return receiver.block()
|
|
}
|
|
|
|
public inline fun <T> T.apply(block: T.() -> Unit): T {
|
|
contract {
|
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
|
}
|
|
block()
|
|
return this
|
|
}
|
|
|
|
public inline fun <T> T.also(block: (T) -> Unit): T {
|
|
contract {
|
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
|
}
|
|
block(this)
|
|
return this
|
|
}
|
|
|
|
public inline fun <T, R> T.let(block: (T) -> R): R {
|
|
contract {
|
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
|
}
|
|
return block(this)
|
|
}
|
|
|
|
public inline fun <T> T.takeIf(predicate: (T) -> Boolean): T? {
|
|
contract {
|
|
callsInPlace(predicate, InvocationKind.EXACTLY_ONCE)
|
|
}
|
|
return if (predicate(this)) this else null
|
|
}
|
|
|
|
public inline fun repeat(times: Int, action: (Int) -> Unit) {
|
|
contract { callsInPlace(action) }
|
|
|
|
for (index in 0..times - 1) {
|
|
action(index)
|
|
}
|
|
} |