Open hamdiallam opened 3 years ago
def unapply[A](a : A): Some[A] = Some(a)
That looks wrong to me, this unapply takes a value of type A and returns a value of type A, did you mean something like:
def unapply[A](a : Baz[A]): Some[A] = ...
Yes, my bad. That was a typo on my end. Updated the description
case Baz(a) => a // ERROR: Found: (a : A$2), Required: A
At this point we should know that A$2 <: A
so that does look like a bug.
Compiler version: 3.01
When defining an unapply for a class that has a parameterized type extending a covariant type, the compiler errors or emits warning when pattern matching on the type.
The only way this works is to make the subtype covariant and matching on the type directly, supplying the generic type.
However, the unapply for a case class works fine. No issues in Scala 2
Example
Case 1
Case 2
This works.