-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closes #4300 adds better worded pattern match unreachability warning #4552
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
allanrenucci
merged 6 commits into
scala:master
from
zoltanelek:4300_zoltanelek-better_worded_pattern_match_reachability_warning
Jun 13, 2018
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
becafe4
Closes #4300 adds better worded pattern match unreachability warning
zoltanelek 6834571
changed pattern match reachability warning, to reflect more complex m…
zoltanelek f55d497
clearer error message for pattern matching on objects
zoltanelek 215f0bf
Created a proper error message case class
zoltanelek bf7c85c
Common TypeTestAlwaysSucceeds warning case class for pattern match an…
zoltanelek 1370dd1
Fixed formatting
zoltanelek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,9 +90,14 @@ object TypeTestsCasts { | |
|
|
||
| if (expr.tpe <:< testType) | ||
| if (expr.tpe.isNotNull) { | ||
| ctx.warning( | ||
| em"this will always yield true, since `$foundCls` is a subclass of `$testCls`", | ||
| expr.pos) | ||
| if (inMatch) | ||
| ctx.warning( | ||
| em"this case will always be taken because the scrutinee has type `$testType`", | ||
| tree.pos) | ||
| else | ||
| ctx.warning( | ||
| em"this will always yield true, since `$foundCls` is a subclass of `$testCls`", | ||
| expr.pos) | ||
|
||
| constant(expr, Literal(Constant(true))) | ||
| } | ||
| else expr.testNotNull | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message doesn't make sense for the following test case:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x: Int(as shown by the position) — I'd prefer in fact "the highlighted pattern match".I think both this message and the current one can still be a bit confusing because they might only refer to one pattern out of many nested ones, but maybe that can be clarified in the message explanation.
I'd also please keep showing both
$foundClsand$testCls, since in the presence of type aliases they might be nontrivial to deduce from the scrutinee type and the pattern match.Separately, "since
$foundClsis a subclass of$testCls" says more than "because the scrutinee has type$testType": who wrote the code and fixes the warning might know the scrutinee's type, but what they probably missed is that$foundClsis a subclass of$testCls.