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

Patternmatch Unreachable Warning #20122

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

Patternmatch Unreachable Warning #20122

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

Comments

@CyrilFMoser
Copy link

Compiler version

3.4.1

Minimized code

sealed trait T_B[C, D]
case class CC_A()
case class CC_B[A, C](a: A) extends T_B[C, CC_A]
case class CC_C[C, D](a: T_B[C, D])
    extends T_B[Int, CC_A]
case class CC_E(a: CC_C[Char, Byte])
val v_a: T_B[Int, CC_A] = CC_B(CC_E(CC_C(null)))
val v_b = v_a match {
  case CC_B(CC_E(CC_C(_))) => 0
  case _              => 1
}

Output

The value of v_b is 0

Expectation

The compiler gives an unreachable warning for case CC_B(CC_E(CC_C(_))), so it should not be able to reach that case.

@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

The unreachable case indeed is reached when this similar repro is run:

// repro-script.sc
sealed trait T_B[C, D]
case class CC_A()
case class CC_B[A, C](a: A) extends T_B[C, CC_A]
case class CC_C[C, D](a: T_B[C, D])
    extends T_B[Int, CC_A]
case class CC_E(a: CC_C[Char, Byte])
val v_a: T_B[Int, CC_A] = CC_B(CC_E(CC_C(null)))
val v_b = v_a match {
  case CC_B(CC_E(CC_C(_))) => 0
  case _              => 1
}
println(s"unreachable case v_b: $v_b")
scala-cli run repro-script.sc
[warn] ./repro-script.sc:9:8
[warn] Unreachable case
[warn]   case CC_B(CC_E(CC_C(_))) => 0
[warn]        ^^^^^^^^^^^^^^^^^^^
unreachable case v_b: 0

@Gedochao Gedochao added 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

Very similar issues which were reported together with this, potentially duplicates:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants