sealed trait EnumVal
val BarA = new EnumVal { val name = "A" }
val BarB = new EnumVal { val name = "B" }
val BarC = new EnumVal { val name = "C" }
Generic[EnumVal]
However we can't guarantee that the anonymous class is assigned to the enclosing val (even if it's a subtype of the sealed trait):
sealed trait T
case class C(i: Int) extends T
val t: T = {
new T { }
C(42)
}
val gen = Generic[T]
println(gen.to(t)) // Inl(C(42))
println(gen.to(C(42))) // Inr(Inl(C(42)))
Having new T { } buried in the local scope of t not only compiles but also changes the behaviour of the program. Quite surprising. Unfortunately we can't have both EnumVal and guard against T.
This is taken from the tests:
However we can't guarantee that the anonymous class is assigned to the enclosing val (even if it's a subtype of the sealed trait):
Having
new T { }
buried in the local scope oft
not only compiles but also changes the behaviour of the program. Quite surprising. Unfortunately we can't have bothEnumVal
and guard againstT
.