milessabin / shapeless

Generic programming for Scala
Apache License 2.0
3.39k stars 533 forks source link

Drop support for Generic anonymous classes #766

Closed joroKr21 closed 2 years ago

joroKr21 commented 7 years ago

This is taken from the tests:

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.

joroKr21 commented 2 years ago

Won't make this breaking change in Shapeless 2