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
Don't warn twice: unreachability warning should suppress nonsensical-comparison warning #5897
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5897?orig=1 |
@paulp said: scala> true match { case true => true ; case false => false ; case _ => false }
<console>:8: warning: unreachable code
true match { case true => true ; case false => false ; case _ => false }
^ (Is "unreachable code" being a warning rather than an error now a short term virtpatmat thing? I think it was better as an error.) |
@VladUreche said: On the other hand, I forgot about the unreachable code warning, which should actually be issued. Thanks for pointing it out! |
@paulp said: if (() == ()) true else false You must have some interesting use case in mind. It's not exactly an "implementation detail" that the pattern matcher calls ==, it's the specification of what pattern matching is. I certainly consider it a feature that it warns in this spot, and would consider it a bug if it did not. The unreachable code warning is born of exactly the same calculus: "this can't possibly be what you meant." |
@VladUreche said: |
@paulp said: If you are saying the error message should be tailored to the original syntax, then I would say absolutely it should. But it sounds like you're saying not to warn at all, and the logic of that escapes me. |
@VladUreche said:
No, no, no, I didn't make it clear enough, sorry: the warning is useless only for the syntax in question, no doubt about its usefulness in the general sense. |
@adriaanm said: $ git diff
diff --git i/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala w/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
index 4e8f416b16..5dc7e02781 100644
--- i/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
+++ w/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
@@ -2357,6 +2357,9 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// TODO: domain of feasibly enumerable built-in types (enums, char?)
def enumerateSubtypes(tp: Type): Option[List[Type]] =
tp.typeSymbol match {
+ case UnitClass =>
+ Some(List(UnitClass.tpe)) scala> () match { case () => true; case _ => false }
<console>:8: warning: unreachable code
() match { case () => true; case _ => false }
^ |
@adriaanm said: |
@VladUreche said: |
@adriaanm said: |
@adriaanm said: |
Couldn't find other examples that trigger the warning.
The text was updated successfully, but these errors were encountered: