W3cubDocs

/Kotlin

Package kotlin.contracts

Experimental DSL for declaring custom function contracts.

Types

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

CallsInPlace

An effect of calling a functional parameter in place.

interface CallsInPlace : Effect
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

ConditionalEffect

An effect of some condition being true after observing another effect of a function.

interface ConditionalEffect : Effect
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

ContractBuilder

Provides a scope, where the functions of the contract DSL, such as returns, callsInPlace, etc., can be used to describe the contract of a function.

interface ContractBuilder
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

Effect

Represents an effect of a function invocation, either directly observable, such as the function returning normally, or a side-effect, such as the function's lambda parameter being called in place.

interface Effect
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

InvocationKind

Specifies how many times a function invokes its function parameter in place.

enum class InvocationKind
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

Returns

Describes a situation when a function returns normally with a given return value.

interface Returns : SimpleEffect
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

ReturnsNotNull

Describes a situation when a function returns normally with any non-null return value.

interface ReturnsNotNull : SimpleEffect
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

SimpleEffect

An effect that can be observed after a function invocation.

interface SimpleEffect : Effect

Annotations

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

ExperimentalContracts

This marker distinguishes the experimental contract declaration API and is used to opt-in for that feature when declaring contracts of user functions.

annotation class ExperimentalContracts

Functions

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

contract

Specifies the contract of a function.

fun contract(builder: ContractBuilder.() -> Unit)

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.contracts/index.html