Skip to content

Commit

Permalink
Modify withError to no longer need suppression
Browse files Browse the repository at this point in the history
  • Loading branch information
kyay10 committed Nov 18, 2024
1 parent 261a348 commit 468ecea
Showing 1 changed file with 1 addition and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -655,19 +655,14 @@ public inline fun <Error, B : Any> Raise<Error>.ensureNotNull(value: B?, raise:
* <!--- TEST lines.isEmpty() -->
*/
@RaiseDSL
@Suppress("WRONG_INVOCATION_KIND")
public inline fun <Error, OtherError, A> Raise<Error>.withError(
transform: (OtherError) -> Error,
@BuilderInference block: Raise<OtherError>.() -> A
): A {
contract {
callsInPlace(transform, AT_MOST_ONCE)
// This is correct, despite compiler complaining, because we don't actually "handle" any errors from `block`,
// we just transform them and re-raise them.
// This can be proven by inlining `recover` and subsequently `fold` and observing that the compiler is happy
callsInPlace(block, EXACTLY_ONCE)
}
return recover(block) { raise(transform(it)) }
recover({ return block(this) }) { raise(transform(it)) }
}

/**
Expand Down

0 comments on commit 468ecea

Please sign in to comment.