Kroppeb
05/29/2019, 10:57 PMinline fun StringReader.tryTo(block: StringReader.TryTo.() -> Unit){
contract {
callsInPlace(block, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
}
try {
it.block()
} catch (e: Exception) {
it.reset()
}
}
And
override fun parse(reader: StringReader): String? {
reader.tryTo {
throw Exception("hi")
}
return null // Marked as unreachable code
}
On a inline lambda seems to not realise that an exception that is thrown in the lambda can be caught in the inlined function. This gets even worse when the return is not nullable and the user doesn't add a return as it is marked as unreachable and as a result at runtime the function will return null.AT_MOST_ONCE
.karelpeeters
05/29/2019, 11:05 PMcallsInPlace
need to be clarified, there's nothing in the docs. Definitely report this on YouTrack.Kroppeb
05/29/2019, 11:09 PMkarelpeeters
05/29/2019, 11:10 PMKroppeb
05/29/2019, 11:12 PMIf this problem occurs only with runCatching I'd say that we should remove contract in 1.3Maybe someone should have actually tested this =P
karelpeeters
05/29/2019, 11:34 PMKroppeb
05/30/2019, 8:54 AMkarelpeeters
05/30/2019, 10:35 AM