Skip to content

false exhaustivity warning for shared inner sealed traits and type parameters #23734

@eejbyfeldt

Description

@eejbyfeldt

Compiler version

3.7.2, 3.3.5

Minimized code

trait Nodes1 {
  sealed trait B
  final case class R1() extends B
}

trait Nodes2 extends Nodes1 {
  final case class R2[T]() extends B
}


object Impl1 extends Nodes1

object test2 {
  val a: Impl1.B = ???
  a match {
    case Impl1.R1() => ???
  }
}

Output

$ ~/Downloads/scala3-3.7.2-x86_64-pc-linux/bin/scalac nodes.scala 
-- [E029] Pattern Match Exhaustivity Warning: nodes.scala:15:2 ----------------------------------------------------------------
15 |  a match {
   |  ^
   |  match may not be exhaustive.
   |
   |  It would fail on pattern case: (Nodes2 & Impl1.type)#R2()
   |
   | longer explanation available when compiling with `-explain`
1 warning found

Expectation

No warnings is produced.

Since Impl1.type is a object instances of Nodes2 & Impl1.type does not exist. Remove the type parameter from R2 makes the warning go away.

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