Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern Match Exhaustiveness Check Misses a Case #20131

Closed
CyrilFMoser opened this issue Apr 8, 2024 · 3 comments · Fixed by #21000
Closed

Pattern Match Exhaustiveness Check Misses a Case #20131

CyrilFMoser opened this issue Apr 8, 2024 · 3 comments · Fixed by #21000
Assignees
Labels
area:pattern-matching area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Milestone

Comments

@CyrilFMoser
Copy link

CyrilFMoser commented Apr 8, 2024

Compiler version

3.4.1

Minimized code

sealed trait T_A
sealed trait T_B[A, B]
case class CC_A[A, C, D](a: T_B[C, D]) extends T_B[A, T_B[C, D]]

case class CC_B() extends T_A
case class CC_C[A, B]() extends T_A
case class CC_D[C, D](b: T_B[C, D], c: T_A)
    extends T_B[CC_A[Int, Byte, Int], T_B[C, D]]

val v_a: T_B[CC_A[Int, Byte, Int], T_B[Char, Char]] = CC_D(null, CC_B())
val v_b: Int = v_a match {
  case CC_A(_)         => 0
  case CC_D(_, CC_C()) => 1
}

Output

Crashes error at runtime

Expectation

Should give a warning at compile time that the pattern match is not exhaustive.

@CyrilFMoser CyrilFMoser added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 8, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Jun 4, 2024

Crashes

I wasn't able to reproduce the crash.
Assuming this to just be a reporting issue.

@Gedochao Gedochao added area:reporting Error reporting including formatting, implicit suggestions, etc area:pattern-matching and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 4, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Jun 4, 2024

Ah, right. There's no crash, but the code fails by throwing an exception at runtime when run as a script.

// repro-script.sc
sealed trait T_A
sealed trait T_B[A, B]
case class CC_A[A, C, D](a: T_B[C, D]) extends T_B[A, T_B[C, D]]

case class CC_B() extends T_A
case class CC_C[A, B]() extends T_A
case class CC_D[C, D](b: T_B[C, D], c: T_A)
    extends T_B[CC_A[Int, Byte, Int], T_B[C, D]]

val v_a: T_B[CC_A[Int, Byte, Int], T_B[Char, Char]] = CC_D(null, CC_B())
val v_b: Int = v_a match {
  case CC_A(_)         => 0
  case CC_D(_, CC_C()) => 1
}
scala-cli run repro-script.sc
Compiling project (Scala 3.4.2, JVM (17))
Compiled project (Scala 3.4.2, JVM (17))
Exception in thread "main" scala.MatchError: CC_D(null,CC_B()) (of class repro$minusscript$_$CC_D)
        at repro$minusscript$_.<init>(repro-script.sc:13)
        at repro$minusscript_sc$.script$lzyINIT1(repro-script.sc:29)
        at repro$minusscript_sc$.script(repro-script.sc:29)
        at repro$minusscript_sc$.main(repro-script.sc:33)
        at repro$minusscript_sc.main(repro-script.sc)

@Gedochao
Copy link
Contributor

Gedochao commented Jun 4, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:pattern-matching area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants