https://kotlinlang.org logo
#kotest
Title
# kotest
m

Marius Kotsbak

06/25/2021, 4:41 PM
Hmm, I don't understand why use of
Copy code
infix fun <B> Either<Any?, B>.shouldBeRight(b: B) = this should beRight(b)
is compiling with whatever type of B that is not compatible with the Either's B type...?
s

sam

06/26/2021, 11:01 PM
Wouldn't type inference just promote B to be the least common bound of the eithers right type and whatever vale you passed into the function
m

Marius Kotsbak

07/05/2021, 11:55 AM
What would they have in common then? B is given by the receiver type?
Maybe because it is defined as
sealed class Either<out A, out B>
?
Here the two B-s were a primitive type and class type, so they should not be compatible at all....
s

sam

07/05/2021, 12:44 PM
They would have Any in common
m

Marius Kotsbak

07/08/2021, 12:21 PM
Hm japp. Anything that could be done to avoid that compiling as it will never work at runtime?
s

sam

07/08/2021, 1:20 PM
There is an experimental annotation we could try
🙌 1
2 Views