I ran into problem type inference with case classes. Here is a minimal example:
trait T[X] case class Thing[A, B, X](a: A, f: A => B) extends T[X] def hmm[X](t: T[X]) = t match { case Thing(a, f) => f("this really shouldn't typecheck") }
Scala decides that a: Any and f: Any => Any , but this is inappropriate; they really should have types a: SomeTypeA and f: SomeTypeA => SomeTypeB , where SomeTypeA and SomeTypeB are unknown types.
Another way of saying that I think the hypothetical Thing.unapply method should look something like this:
def unapply[X](t: T[X]): Option[(A, A => B)] forSome { type A; type B } = { t match { case thing: Thing[_, _, X] => Some((thing.a, thing.f)) } }
This version correctly gives a type error in f("this really shouldn't typecheck") .
Does this sound like a compiler error, or am I missing something?
Edit: this is on Scala 2.10.3.
types scala
Alan O'Donnell
source share