Skip to content

Pattern Match Loses Type Information #16885

@adamgfraser

Description

@adamgfraser

Compiler version

3.2.2

Minimized code

sealed trait Foo[+A] {
  def baz: A
}

sealed trait Bar[+A] extends Foo[A]

object Bar {
  def unapply[A](bar: Bar[A]): Some[A] =
    Some(bar.baz)
}

def someMethod[A](foo: Bar[A]): A =
  ???

def test[A](foo: Foo[A]): A =
  foo match {
    case bar @ Bar(_) => someMethod(bar)
  }

Output

Found:    (bar : Playground.Foo[A] & Playground.Bar[Any])
Required: Playground.Bar[A]

Expectation

I would expect that the inferred type of bar here would be Bar[A] instead of Bar[Any]. This is the behavior in Scala 2 so this seems to be a regression in type inference

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions