Skip to content

"Unreachable case" is, in fact, reachable #23113

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

Open
durban opened this issue May 7, 2025 · 1 comment · May be fixed by #23292
Open

"Unreachable case" is, in fact, reachable #23113

durban opened this issue May 7, 2025 · 1 comment · May be fixed by #23292
Labels
area:pattern-matching area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug

Comments

@durban
Copy link

durban commented May 7, 2025

Compiler version

3.3.5

Minimized code

package com.example

object Repro {

  sealed abstract class Listener[A]

  final case class Empty[A]()
    extends Listener[A]

  final case class Waiting[A](next: Promise[A])
    extends Listener[A]

  def foo[A](l: Listener[A]): Unit = {
    l match {
      case Empty() => println("empty")
      case w @ Waiting(_) => println(s"waiting: ${w.next}") // <-- HERE
    }
  }

  def main(args: Array[String]): Unit = {
    foo(Waiting(Promise()))
  }
}

sealed trait Promise[A]

object Promise {

  def apply[A](): Promise[A] = new PromiseImpl[A](null)

  private[this] abstract class PromiseBase[A] extends Promise[A]

  private[this] final class PromiseImpl[A](val st: Waiting[A]) extends PromiseBase[A]

  private[this] final class Waiting[A]
}

Output

[warn] -- [E030] Match case Unreachable Warning: /home/.../Repro.scala:... 
[warn] 33 |      case w @ Waiting(_) => println(s"waiting: ${w.next}")
[warn]    |           ^^^^^^^^^^^^^^
[warn]    |           Unreachable case
[warn] Matching filters for @nowarn or -Wconf:
[warn]   - id=E30
[warn]   - name=MatchCaseUnreachable
[warn] one warning found
[info] running com.example.Repro 
waiting: com.example.Promise$PromiseImpl@d3995d

Expectation

I'd expect no "Unreachable case" warning for a case which is reachable.

@durban durban added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 7, 2025
@som-snytt
Copy link
Contributor

It's quiet for case w: Waiting[?] =>.

Maybe there's something special about Scala 3 pattern matching, but this looks like it should be easy. Speaking as a peanut gallery member.

@Gedochao Gedochao added area:reporting Error reporting including formatting, implicit suggestions, etc area:pattern-matching better-errors Issues concerned with improving confusing/unhelpful diagnostic messages and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 7, 2025
nox213 added a commit to nox213/scala3 that referenced this issue May 30, 2025
@nox213 nox213 linked a pull request May 30, 2025 that will close this issue
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 better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants