Why pattern matching on Seq doesn't emit warning when type check is fruitless?

In the following example (scastie):

class Foo

object Foo1 extends Foo
object Foo2 extends Foo

class Bar
object Bar {
  def unapply(bar: Bar): Option[Foo] = Some(Foo1)
}

new Bar match {
  case Bar(Seq(1)) => "compiles no warning"
  case Bar(List(1)) => "compiles with warning"
  case Bar(Foo2) => "oh no :("
  case Bar(Foo1) => "hooray!"
}

Only the Bar(List(1)) pattern match yields a “fruitless type test” warning, while the Seq match doesn’t.

Why is that?

Edit

This behavior seems to not be limited to Seq, but to any trait with unapply:

trait Bazz
object Bazz {
  def unapply(bazz: Bazz): Option[Int] = Some(1)
}

new Bar match {
  case Bar(Bazz(1)) => "compiles no warning"
  case Bar(Foo2) => "oh no :("
  case Bar(Foo1) => "hooray!"
}
1 Like

Because it’s not fruitless. Bar.unapply could return a Foo with Seq[Int] (but it cannot return a Foo with List[Int] because both Foo and List are classes).

3 Likes

Yep, that makes sense. I’m assuming pattern matching desugars into isInstanceOf, which can never be said to be fruitless when checking for traits.