diff --git a/plugins/formal-verification/testData/diagnostics/good_contracts/stdlib_replacement_tests.kt b/plugins/formal-verification/testData/diagnostics/good_contracts/stdlib_replacement_tests.kt index abe7fe347cb27..ec67c5c531fbf 100644 --- a/plugins/formal-verification/testData/diagnostics/good_contracts/stdlib_replacement_tests.kt +++ b/plugins/formal-verification/testData/diagnostics/good_contracts/stdlib_replacement_tests.kt @@ -1,17 +1,33 @@ // REPLACE_STDLIB_EXTENSIONS +// ALWAYS_VALIDATE -import kotlin.contracts.contract -import kotlin.contracts.ExperimentalContracts +import org.jetbrains.kotlin.formver.plugin.verify -@OptIn(ExperimentalContracts::class) -fun useRepeat(): Unit { - contract { - returns() - } +fun useChecks(): Unit { check(true) check(true) { "Lazy message" } } // TODO: add test for `repeat` (we actually have a bug there because we require unsatisfied precondition in loops) -// TODO: add tests for `let`, `apply`, `with`, `run`, `also` +fun useRuns(x: Int): Unit { + verify(run { x + 1 } == 1 + x) + verify(x.run { plus(1) } == 1 + x) +} + +fun useAlso(x: Int): Unit { + (x + 1).also { verify(it == 1 + x) } +} + +fun useLet(x: Int): Unit { + verify(x.let { it + 1 } == 1 + x) +} + +fun useWith(x: Int): Unit { + with(x + 1) { verify(this == 1 + x) } +} + +fun useApply(x: Int): Unit { + (x + 1).apply { verify(this == 1 + x) } +} + diff --git a/plugins/formal-verification/testData/stdlibReplacements.kt b/plugins/formal-verification/testData/stdlibReplacements.kt index 4184c246074cc..1719af5fa4105 100644 --- a/plugins/formal-verification/testData/stdlibReplacements.kt +++ b/plugins/formal-verification/testData/stdlibReplacements.kt @@ -1,5 +1,4 @@ import org.jetbrains.kotlin.formver.plugin.NeverConvert -import org.jetbrains.kotlin.formver.plugin.verify @NeverConvert inline fun run(block: () -> T): T = block() @@ -17,7 +16,7 @@ inline fun T.also(block: (T) -> Unit): T { inline fun T.let(block: (T) -> R): R = block(this) @NeverConvert -inline fun T.apply(block: T.() -> Unit): T = { +inline fun T.apply(block: T.() -> Unit): T { this.block() return this }