Skip to content

Conversation

@liufengyun
Copy link
Contributor

Fix #4225: always check redundant cases except for @unchecked

def test(x: Int) =
x match {
case Bar(a) => a
case _ => x // should be unreachable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test case for objects:

object Bar {
  def unapply(x: String): Some[Int] =
    Some(0)
}

object Test {
  def test(x: String) =
    x match {
      case Bar(a) => a
      case _ => x // this case is reachable, i.e. test(null)
    }
}

Copy link
Contributor Author

@liufengyun liufengyun Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allanrenucci : the exhaustivity check both in Dotty and Scalac ignores null. Otherwise, all pattern matchess without a _ will not be exhaustive. Thus in the example above, both Dotty & Scalac will report a warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was wrong, for reachability check we can handle null thus avoid the warning:

It's implemented in https://github.com/lampepfl/dotty/compare/master...dotty-staging:fix-4225?expand=1#diff-5353f08e8d531fe0ee59335438e6cf7a.

@liufengyun
Copy link
Contributor Author

Close, it can be reviewed in #4233 .

@liufengyun liufengyun closed this Apr 3, 2018
@liufengyun liufengyun deleted the fix-4225 branch April 3, 2018 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants