Compiler version
3.3.4
“-source:future-migration”
Compiler generates a warning on this code and I know why, but I’m not sure this is ok.
When you match on Any - just cast to Matchable, but in this case it creates a mess with nested matches.
Also is there a way to supress these exact warnings? OSS libraries currently produce them intensively and this blocks adding -source:future
option
Minimized code
sealed trait DiffResult extends Product with Serializable
case class DiffResultAdditional[T](value: T) extends DiffResult
case class Foo()
val diffResult: DiffResult = DiffResultAdditional(1)
diffResult match {
case DiffResultAdditional(foo: Foo) => println("hello")
case _ => println("boo")
}
Output
Compiles with warning:
pattern selector should be an instance of Matchable,
but it has unmatchable type T$1 instead
This works, but it makes your code a mess
diffResult match {
case DiffResultAdditional(value) =>
value.asInstanceOf[Matchable] match {
case foo: Foo => println("hello")
}
case _ => println("boo")
}
Expectation
compiles without warning