Skip to content

Missing warning for unreachable case when matching on a tuple #12530

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
smarter opened this issue May 19, 2021 · 0 comments · Fixed by #12533
Closed

Missing warning for unreachable case when matching on a tuple #12530

smarter opened this issue May 19, 2021 · 0 comments · Fixed by #12533

Comments

@smarter
Copy link
Member

smarter commented May 19, 2021

Compiler version

Scala pre-3.0.1 at commit c1eaf8c

Minimized code

object Test {
  def foo(a: Boolean, b: Boolean): Unit =
    (a, b) match {
      case (false, _) =>
      case (true,  _) =>
      case (_, false) => // unreachable
    }
}

Output

No warning

Expectation

Emit an unreachable case warning like Scala 2 does:

warning: unreachable code
      case (_, false) => // unreachable
                      ^

However, note that Scala 2 also fails to emit such a warning in a more complex example:

object Test {
  def foo(a: Option[Boolean], b: Boolean): Unit =
    (a, b) match {
      case (Some(false), _) =>
      case (Some(true), _) =>
      case (None, _) =>
      case (_, false) => // unreachable
    }
}

In Scala 3 the issue seems to be that tuples are not considered to be decomposable types, but I don't know if this is intentional to avoid a complexity blow up /cc @liufengyun

liufengyun added a commit to dotty-staging/dotty that referenced this issue May 19, 2021
liufengyun added a commit to dotty-staging/dotty that referenced this issue May 19, 2021
liufengyun added a commit to dotty-staging/dotty that referenced this issue May 19, 2021
@liufengyun liufengyun self-assigned this May 20, 2021
liufengyun added a commit that referenced this issue May 23, 2021
Fix #12530: Wildcard of value types don't cover null
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
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.

3 participants