Dimitri
Dimitri

Reputation: 1786

No type erasure warning on partial function with abstract type

The following definition doesn't trigger any warning on scala 2.10.4:

class NoWarning[T] {
  def f: PartialFunction[Any, T] = { case x: List[T] => x.head }
}

However this one does (as expected) on scala 2.10.4, but not on 2.11.1:

class WithWarning {
  def f[T]: PartialFunction[Any, T] = { case x: List[T] => x.head }
}
  1. Why does the first definition not trigger a warning at all?
  2. Why does the second definition not trigger a warning on scala 2.11.1?

Upvotes: 4

Views: 166

Answers (1)

som-snytt
som-snytt

Reputation: 39577

Odersky explains a difference in pattern matching depending on whether the type param is on the method or class.

I assume that's because of subclassing.

Upvotes: 0

Related Questions