Breaking match change from Scala 2 to 3 that is too silent

Consider the following code:

object MatchTest { 
  val a: Array[Long] = Array(1L)

  def test(x: Any) = x match { 
    case Array(i: Long) => println("Success!")
    case _              => println("Failure!") }

  def main(args: Array[String]): Unit = test(a) }

When run under Scala 2.13.8 this produces Success whereas under Scala 3.1.1 it produces Failure. For the latter it does not matter if the compiler option -source:3.0-migration is used.

If the change is intended, this should at least produce a big fat warning that the match will possibly fail. If it is not intended, well … it’s even worse, for this significantly changes runtime behaviour after migration. I could not find a page in the migration documentation discussing this (the matchable trait page is related, but addresses a different problem).

Btw, if you replace the relevant Array by IArray the result is again Success, but gives other warnings.


Looks like a bug. Please open an issue at Issues · lampepfl/dotty · GitHub.


Thanks for confirming, entry can be found under Missed match on Array(1L) in Scala 3.1.1


This kind of runtime behavior change is very dangerous,thanks.