Skip to content

no exhaustiveness check for subtypes of sealed hierarchies #24246

@road21

Description

@road21

Compiler version

all I tested Scala 3:
3.3.7, 3.4.3, 3.5.2, 3.6.4, 3.7.3

works in Scala 2.13.17

Minimized code

//> using scala 3.7.3

trait X

sealed trait Y
case object YY extends Y, X
case object ZZ extends Y, X

def foo[A <: X & Y](x: A): Unit =
  x match {
    case YY => ()
  }

foo(ZZ)

https://scastie.scala-lang.org/road21/DXVR0WnlSTO0pXmoKgKVpQ/1

Output

Exception in thread "main" scala.MatchError: ZZ (of class model$_$ZZ$)

Expectation

[warn] It would fail on the following input: ZZ
[warn]   x match {
[warn]   ^

It works in Scala 2:

//> using scala 2

trait X

sealed trait Y
case object YY extends Y with X
case object ZZ extends Y with X

def foo[A <: X with Y](x: A): Unit =
  x match {
    case YY => ()
  }

foo(ZZ)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions