Skip to content

Using language.experimental.subCases interferes with pattern match exhaustivity checking #25234

@ppurang

Description

@ppurang

Compiler version

Scala CLI version: 1.12.2
Scala version (default): 3.8.1

Minimized code

//> using scala 3.8.1
//> using options -deprecation -feature -Wunused:all -Werror

import language.experimental.subCases

case class NotFound(id: String)
enum AcceptError:
  case IsCancelled(id: String)
  case Denial
case object CatastrophicError
type Error = NotFound | AcceptError | CatastrophicError.type

import AcceptError.*

def errorToString : Error => String =
  case NotFound(id) => s"NotFound: $id"
  case CatastrophicError => s"It is all doom"
  case ae if ae match    //this shouldn't trigger non-exhaustive warning ..
      case Denial => s"In Denial"
      case IsCancelled(id) => s"IsCancelled: $id"

@main def start =
  val e = Denial
  println(errorToString(e))

Output

> scala-cli run -w sub-cases.scala

Compiling project (Scala 3.8.1, JVM (21))
[error] ./sub-cases.scala:17:3
[error] match may not be exhaustive.
[error] 
[error] It would fail on pattern case: AcceptError.IsCancelled(_), Denial
[error]   case NotFound(id) => s"NotFound: $id"
[error]   ^
Error compiling project (Scala 3.8.1, JVM (21))
In Denial
Program exited with return code 0.
Watching sources, press Ctrl+C to exit, or press Enter to re-run.

Expectation

Expect it to be exhaustive i.e. equivalent to compiler's behaviour when encountering this:

def errorToString : Error => String =
  case NotFound(id) => s"NotFound: $id"
  case CatastrophicError => s"It is all doom"
  case Denial => s"In Denial"
  case IsCancelled(id) => s"IsCancelled: $id"

Another bothersome thing: Compiler spits out the warning as an error but the code is still run. Note the lines in the output:

Error compiling project (Scala 3.8.1, JVM (21))
In Denial
Program exited with return code 0.

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