Either and Try lack "extends Product with Serializable" which causes unnecessarily large types

298 views
Skip to first unread message

Simon Ochsenreither

unread,
Feb 22, 2015, 9:14:21 PM2/22/15
to scala-i...@googlegroups.com
This seems to be yet another case where where subtypes of a sealed supertype cause larger-than-necessary types due to missing types in the common parent:

scala> List(Left(1), Right(1))
res0: List[Product with Serializable with scala.util.Either[Int,Int]] = List(Left(1), Right(1))

scala> List(Success(1), Failure(new NullPointerException))
res1: List[Product with Serializable with scala.util.Try[Int]] = List(Success(1), Failure(java.lang.NullPointerException))


I think analogous to the reasoning in https://issues.scala-lang.org/browse/SI-7402 and https://issues.scala-lang.org/browse/SI-7403, Either and Try should extend Product and Serializable itself too.

If we agree that this is the right thing to do, I'll fix it. Tickets: https://issues.scala-lang.org/browse/SI-9173 https://issues.scala-lang.org/browse/SI-9174

(Maybe it would make sense to have some lint warning for this, which says "you have a sealed hierarchy, and here are the parents of all subtypes which are not a parent of the sealed root of this hierarchy: ..."?)

Adriaan Moors

unread,
Feb 23, 2015, 2:00:32 PM2/23/15
to scala-i...@googlegroups.com
On Sun, Feb 22, 2015 at 6:14 PM, Simon Ochsenreither <simon.och...@gmail.com> wrote:

(Maybe it would make sense to have some lint warning for this, which says "you have a sealed hierarchy, and here are the parents of all subtypes which are not a parent of the sealed root of this hierarchy: ..."?)

Adriaan Moors

unread,
Feb 23, 2015, 2:01:34 PM2/23/15
to scala-i...@googlegroups.com
On Sun, Feb 22, 2015 at 6:14 PM, Simon Ochsenreither <simon.och...@gmail.com> wrote:

I think analogous to the reasoning in https://issues.scala-lang.org/browse/SI-7402 and https://issues.scala-lang.org/browse/SI-7403, Either and Try should extend Product and Serializable itself too.

If we agree that this is the right thing to do, I'll fix it. Tickets: https://issues.scala-lang.org/browse/SI-9173 https://issues.scala-lang.org/browse/SI-9174


Yes, this should be consistent. The natural lub of `Left` and `Right` is `Either`, the rest is noise.
Reply all
Reply to author
Forward
0 new messages