sealed class Either<A, B>
abstract class Left<A>(val value: A) : Either<A, Nothing>()
abstract class Right<B>(val value: B) : Either<Nothing, B>()
class MySubclass<A>(valueA: A) : Left<A>(valueA)
fun <A,B> myfunction(value: Either<A, B>) {
println(value)
}
It’s correct, not a language bug. You said “MySubclass”, and I assume you mean “MyFarm”. If you add out to the type parameter in Either, to mark the type parameter as covariant, then your code will compile.
sealed class Either<Animal, out Plants>
...
val f = MyFarm()
myFunction(f)
A Nothing is a subtype of Rose, but unless the type parameter is covariant, a Thing<Nothing> is not a subtype of Thing<Rose>. Probably you want to mark both type parameters.