Scala模式匹配推断`Any`而不是存在类型,打破类型安全?

Ala*_*ell 7 types scala

我遇到了案例类令人费解的类型推理问题.这是一个最小的例子:

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")
}
Run Code Online (Sandbox Code Playgroud)

斯卡拉决定a: Anyf: Any => Any,但是这是不恰当的; 他们真的应该有类型的a: SomeTypeAf: SomeTypeA => SomeTypeB,其中SomeTypeASomeTypeB未知类型.

另一种说法是我认为假设的Thing.unapply方法看起来应该是这样的

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))
  }
}
Run Code Online (Sandbox Code Playgroud)

此版本正确地给出了类型错误f("this really shouldn't typecheck").

这看起来像编译器中的错误,还是我错过了什么?

编辑:这是在Scala 2.10.3上.

Kri*_*mbe 3

Mark Harrah 在 Freenode 的 #scala 频道中指出了这一点:是的,这是一个错误。

https://issues.scala-lang.org/browse/SI-6680