Open mateuszjarzyna opened 4 months ago
I've created isRight2
function
@OptIn(ExperimentalContracts::class)
private fun <A, B> Either<A, B>.isRight2(): Boolean {
contract {
returns(true) implies (this@isRight2 is Right<B>)
returns(false) implies (this@isRight2 is Left<A>)
}
return this@isRight2 is Right<B>
}
that works as expected.
So it seems like there is some kind of bug in smart casting with isRight/isLeft methods
This is a known problem in Kotlin 1.x, where smart casting does not always work with generic types like Either
.
@mateuszjarzyna Does this problem also reproduce with Kotlin 2.0?
I have extremely simple code, it's a function that returns
Either<SomeError, CommandResult>
My case is that I liked to check if a course was created, but contract/smart cast seems to not work
The
CommandResult
is a pretty simple interface with two implementationsAnd OwlerError is another interface
I use arrow-kt in version
"1.2.4"
And the screenshot from my IDE showing that smart casting does not work corretly.
If it is relevant here is full list of dependencies