scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Better type inference in pattern alternatives #8881

Open scabug opened 10 years ago

scabug commented 10 years ago

In the following example, the last case is inferred to be of type Any (and therefore does not compile), whereas for both checks T is a common supertype:

object X extends App {

  def f(a: Any): Unit = a match {
    case a: T1 =>
      g(a)
    case a @ (_: T with S) =>
      g(a)
    case a @ (_: T with S | _: T1) =>
      g(a)
  }
  def g(t: T): T = t
}

trait S
trait T
trait T1 extends T
scabug commented 10 years ago

Imported From: https://issues.scala-lang.org/browse/SI-8881?orig=1 Reporter: @sschaef Affected Versions: 2.11.2

SethTisue commented 9 months ago

Scala 3.3.1 accepts it.