-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4661: Missing unreachable case warnings #4869
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
Conversation
@liufengyun this is the fix we discussed in #4661 but it introduces a failure in https://github.com/lampepfl/dotty/blob/ba2eafcf9e7f4d166fe3721d81506a0ab0fb3adf/tests/patmat/file.scala The failure is that we now issue a warning that only null is matched for the last case:
However, looking at the code it's clear that the wildcard case matches more than If we look at that last wildcard case, we can print what's covered before and what's covered by the wildcard:
which seems correct. However, the problem appears when we substract what's already covered from what the
We can see that the The result is empty, which is incorrect. In particular, when we try to decompose the
The first line seems correct, but I don't understand the second line, and I think it's incorrect and caused by a bug in In summary, I think this change uncovered an already-existing bug. Thoughts? |
I'd propose that I patch the failing test and file a separate bug to investigate |
@@ -294,16 +294,21 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { | |||
|
|||
override def intersectUnrelatedAtomicTypes(tp1: Type, tp2: Type) = { | |||
val and = AndType(tp1, tp2) |
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 could be moved to the else branch
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.
Done
My 2 cents: even if this uncovers an existing bug (and I agree with you that it seems to be the case), that bug seems serious enough (or at least, worse than the one fixed here) that we might want to block this fix, at least until we understand what is going on. After all, the failing test does not look that esoteric. EDIT: after looking at the code and at #3939, it seems that it is meant to return EDIT2: this PR looks unobjectionable itself, but I'd still prefer to wait for a clue on how to fix the underlying issue. |
@abeln I confirm that there is a problem with the handling of Thanks a lot. |
Filed #4880 for the related bug. |
@liufengyun disabled the problematic part of the failing test. |
There are a bunch of warnings (that I guess are converted into errors) from For example
Why is the code written in this style (i.e. the type alias and then the pattern matching)? What's the goal of the wildcard |
This seems to be for historical reasons. You can update the code. E.g. def unapply(x: Id) = Some(x.name.toString) |
You can also remove the comment. |
05b667c
to
278ce9c
Compare
@liufengyun I re-enabled the test. So I think this PR is blocked by #4880 |
The changes in |
@liufengyun after rebasing over #4897 both the failing test and the bootstrapped compilation now succeed. So I'll wait for #4897 to get merged before updating the PR. |
@abeln Just merged #4897, and #4904 was merged few days ago. Might be good to also test this keeps working when types are defined under a prefix, for instance trait Prefix {
trait Foo
class One extends Foo
class Two extends Foo
class Three extends Foo
}
class Test(p: Prefix) {
import p._
def test(f: Foo) = f match {
case f: Foo =>
case f: One =>
case f: Two =>
case f: Three =>
}
} Matching against |
278ce9c
to
1f836e5
Compare
@Blaisorblade Just updated the PR. Things still seem to work. I also expanded the new unit test with your prefix cases. Thanks! |
@@ -0,0 +1 @@ | |||
14: Match case Unreachable |
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 is new, and related to #4880, but seems correct: https://github.com/lampepfl/dotty/blob/master/tests/patmat/i4880a.scala#L14
@@ -0,0 +1,61 @@ | |||
trait Foo |
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.
@Blaisorblade I can break this up into smaller tests, if you want. Not sure want the convention is.
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.
Otherwise, LGTM
// Precondition: !isSubType(tp1, tp2) && !isSubType(tp2, tp1) | ||
if (tp1 == nullType || tp2 == nullType) { | ||
// Since projections of types don't include null, intersection with null is empty. | ||
Empty |
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.
A minor comment: it seems more readable if we just return Empty
for the exceptional case, fewer braces and indentations.
1f836e5
to
a1be0cd
Compare
@liufengyun you're right. That's better. Done. |
LGTM, thanks a lot @abeln ! |
No description provided.