Are warnings ok when matching on generic types?

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

A wild guess :

case _ : DiffResultAdditional(foo: Foo) => println("hello")

Ordinary -Wconf works for suppression.

'-Wconf:msg=pattern selector should be an instance of Matchable:s'

I see it wants

case class DiffResultAdditional[T <: Matchable](value: T) extends DiffResult

but I haven’t spent time with past Dotty to know what it means, let alone future Dotty.

There must also be a ghost of Dotty present, which haunts us this very night.

Edit: the explain says for the less gruesome

import compiletime.asMatchable
  diffResult match
    case DiffResultAdditional(foo) =>
      println("hello")
      foo.asMatchable match
      case _: Foo => println("world")

Thank you! It sure ok that it wants something, but this is library code, I have no access to it :slight_smile: