Skip to content

False-positive unreachable case warning #19359

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

Closed
arainko opened this issue Jan 3, 2024 · 0 comments · Fixed by #19397
Closed

False-positive unreachable case warning #19359

arainko opened this issue Jan 3, 2024 · 0 comments · Fixed by #19397

Comments

@arainko
Copy link
Contributor

arainko commented Jan 3, 2024

Compiler version

3.3.1, 3.4.0-RC1-bin-20231223-938d405-NIGHTLY

Minimized code

//> using scala 3.3.1

sealed trait Plan[+E <: Plan.Error, +F[+e <: E] <: Plan.Fallible[e]]

object Plan {
  case class Upcast() extends Plan[Nothing, Nothing]
  case class BetweenProducts[+E <: Plan.Error, +F[+e <: E] <: Plan.Fallible[e]](fields: List[Plan[E, F]]) extends Plan[E, F]
  case class Error() extends Plan[Plan.Error, Nothing]
  case class Fallible[+E <: Plan.Error]() extends Plan[E, Plan.Fallible]
}

@main def main = {
  val erroneousNotFallible: Plan[Plan.Error, Nothing] = Plan.BetweenProducts(Nil)
  
  erroneousNotFallible match
    case Plan.Upcast() => println("not boom")
    case Plan.BetweenProducts(fields) => println("reachable after all")
    case Plan.Error() => println("not boom")
}

Output

Compiling project (Scala 3.3.1, JVM (11))
[warn] ./Repro.scala:17:10
[warn] Unreachable case
[warn]     case Plan.BetweenProducts(fields) => println("reachable after all")
[warn]          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compiled project (Scala 3.3.1, JVM (11))
reachable after all

Expectation

No unreachable case warning.

@arainko arainko added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 3, 2024
@nicolasstucki nicolasstucki added area:pattern-matching and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 8, 2024
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
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