Effects: add test on (de)serialization of contracts
- 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
This commit is contained in:
+65
@@ -0,0 +1,65 @@
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user