Skip to content

Commit c39888e

Browse files
committed
Add test case for #96
1 parent 3a50dfa commit c39888e

File tree

2 files changed

+21
-1
lines changed
  • kotlin-result/src

2 files changed

+21
-1
lines changed

Diff for: kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Binding.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public inline fun <V, E> binding(crossinline block: BindingScope<E>.() -> V): Re
3333
return with(BindingScopeImpl<E>()) {
3434
try {
3535
Ok(block())
36-
} catch (ex: BindException) {
36+
} catch (_: BindException) {
3737
result!!
3838
}
3939
}

Diff for: kotlin-result/src/commonTest/kotlin/com/github/michaelbull/result/BindingTest.kt

+20
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,24 @@ class BindingTest {
7878
actual = result,
7979
)
8080
}
81+
82+
@Test
83+
fun runCatchingInsideBindingDoesNotSwallow() {
84+
fun squareNumber(): Result<Int, BindingError> = throw RuntimeException()
85+
86+
val squaredNumbers = binding<List<Int>, BindingError> {
87+
val result: Result<List<Int>, Throwable> = runCatching {
88+
(0..<10).map { number ->
89+
squareNumber().bind()
90+
}
91+
}
92+
93+
result.mapError { BindingError }.bind()
94+
}
95+
96+
assertEquals(
97+
expected = Err(BindingError),
98+
actual = squaredNumbers,
99+
)
100+
}
81101
}

0 commit comments

Comments
 (0)