bug icon indicating copy to clipboard operation
bug copied to clipboard

Better type inference in pattern alternatives

Open scabug opened this issue 11 years ago • 2 comments

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 avatar Oct 05 '14 17:10 scabug

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

scabug avatar Oct 05 '14 17:10 scabug

Scala 3.3.1 accepts it.

SethTisue avatar Feb 12 '24 19:02 SethTisue