No type erase warning for partial function with abstract type

The following definition does not raise any warnings on scala 2.10.4:

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

However, this 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 }
}
  • Why does the first definition not trigger a warning at all?
  • Why does the second definition not trigger a warning on scala 2.11.1?
+4
source share
1 answer

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

I guess because of the subclass.

0
source

Source: https://habr.com/ru/post/1546921/


All Articles