Skip to content

Commit

Permalink
Fix InvocationKind contract warnings
Browse files Browse the repository at this point in the history
IntelliJ has started warning about these in K2 mode.

Closes #106
  • Loading branch information
Daiji256 authored and michaelbull committed Dec 22, 2024
1 parent 9ca1092 commit 4a0c7dd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import kotlin.contracts.contract
*/
public suspend inline fun <V, E> coroutineBinding(crossinline block: suspend CoroutineBindingScope<E>.() -> V): Result<V, E> {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}

lateinit var receiver: CoroutineBindingScopeImpl<E>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlin.contracts.contract
*/
public inline fun <V> runSuspendCatching(block: () -> V): Result<V, Throwable> {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}

return runCatching(block).throwIf {
Expand All @@ -33,7 +33,7 @@ public inline fun <V> runSuspendCatching(block: () -> V): Result<V, Throwable> {
*/
public inline infix fun <T, V> T.runSuspendCatching(block: T.() -> V): Result<V, Throwable> {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}

return runCatching(block).throwIf {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import kotlin.contracts.contract
*/
public inline fun <V, E> binding(crossinline block: BindingScope<E>.() -> V): Result<V, E> {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}

return with(BindingScopeImpl<E>()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlin.contracts.contract
*/
public inline fun <V> runCatching(block: () -> V): Result<V, Throwable> {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}

return try {
Expand All @@ -27,7 +27,7 @@ public inline fun <V> runCatching(block: () -> V): Result<V, Throwable> {
*/
public inline infix fun <T, V> T.runCatching(block: T.() -> V): Result<V, Throwable> {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}

return try {
Expand Down

0 comments on commit 4a0c7dd

Please sign in to comment.