Skip to content

Fix #3144: more aggressively check unreachability #3891

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

Merged
merged 4 commits into from
Jan 29, 2018

Conversation

liufengyun
Copy link
Contributor

@liufengyun liufengyun commented Jan 23, 2018

Fix #3144: more aggressively check unreachability.

Previously, we optimise by (1) skipping the check for the first clause; (2) don't intersect with the scrutinee type.

Based on #3888.

@allanrenucci
Copy link
Contributor

Regarding (2), I think we should keep the old behavior under scala2 mode. Related #3208

@liufengyun
Copy link
Contributor Author

@allanrenucci Thanks for the pointer. The intersect in this PR is different from the issues discussed in #3208. Current PR only changes exhaustivity check, type checking of patmat remains the same.


// starts from the second, the first can't be redundant
(1 until cases.length).foreach { i =>
(0 until cases.length).foreach { i =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you could iterate over cases.inits instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I didn't know inits before, I'll consider use it later. In the current case, I do need i to get the current clause, init doesn't help much here.

Sealed classes and traits are effectively inhabited in
practice. By treating them as inhabited by default,
we avoid spurious warnings that ignore anonymous classes.

When we have a mechanism to track anonymous children or
disallow anonymous children for sealed classes, we
could revert this change to make the check stronger.
@liufengyun liufengyun merged commit f029755 into scala:master Jan 29, 2018
@liufengyun liufengyun deleted the fix-3144 branch January 29, 2018 14:04
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.

3 participants