In the current implementation, we have useful translation rules for ADTs such as Option:
enum Option[+T]:
case Some(x: T)
case None
is equivalent more or less, to:
enum Option[+T]:
case Some(x: T) extends Option[T]
case None extends Option[Nothing]
From experiments, however, it’s not so useful for ADTs such as Result:
enum Result[+A]:
case Success(a: A)
case Failure(err: String)
Which is equivalent, more or less, to:
enum Result[+A]:
case Success(a: A) extends Result[A]
case Failure(err: String) extends Result[A]
It would probably be possible to infer that Failure is a Result[Nothing] since none of its fields is of type A, rather than limit the heuristic to does it have fields?.
It would probably be possible to extend the heuristic further, for types like Either:
enum Either[+A, +B]:
case Left(a: A)
case Right(b: B)
This could be equivalent to:
enum Either[+A, +B]:
case Left(a: A) extends Either[A, Nothing]
case Right(b: B) extends Either[Nothing, B]
I realise that this might be a breaking source and TASTY change (mostly because @smarter straight up told me), so this might be a hard sell.
