Skip to content

Type pattern doesn’t narrow type #8800

Closed
@julienrf

Description

@julienrf

(tested with 0.23.0-RC1 only, maybe it has already been fixed upstream?)

Minimized code

sealed trait Foo
case object Qux extends Foo

def problem(foo: Foo): Qux.type = foo match {
  case qux: Qux.type => qux
}

https://scastie.scala-lang.org/yJbmLhdYTNivTXwKg4E1wQ

Output

[error] -- [E007] Type Mismatch Error: 
[error]    |        case qux: Qux.type => qux
[error]    |                              ^^^
[error]    |               Found:    (qux : Foo)
[error]    |               Required: Qux.type

Expectation

qux should have type Qux.type instead of Foo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions