uhe
08/24/2020, 2:27 PMResult
as a return type and ran into a weird issue. Does anybody know if this is already known? I couldn't find anything in the issue tracker.
suspend fun foo() = suspendCancellableCoroutine<Unit> {
thread {
it.resumeWithException(RuntimeException("foo"))
}
}
suspend fun fooWithResult(): Result<Unit> = runCatching { foo() }
@Test
fun resultTest() = runBlocking {
// when fooWithResult is not inlined the exception is not caught by "runCatching"
val result = fooWithResult()
Assertions.assertTrue { result.isFailure }
delay(5000)
Unit
}
The test passes if I mark fooWithResult
as inline. Without it the exception is not caught by runCatching
araqnid
08/24/2020, 2:48 PMuhe
08/24/2020, 2:51 PMcompileKotlin {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += ["-Xinline-classes", "-Xallow-result-return-type"]
}
}
uhe
08/24/2020, 2:52 PMuhe
08/24/2020, 2:53 PMIlmir Usmanov [JB]
08/24/2020, 5:08 PM"-Xallow-result-return-type"Do not do this. The error is here to prevent exactly this behavior until the proper fix is implemented.
uhe
08/24/2020, 5:13 PM