Scala Programming Language
  1. Scala Programming Language
  2. SI-5897

Don't warn twice: unreachability warning should suppress nonsensical-comparison warning

    Details

      Description

      $ scala
      Welcome to Scala version 2.10.0-20120609-095502-c9602af1d7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_32).
      Type in expressions to have them evaluated.
      Type :help for more information.
      
      scala> () match { case () => true; case _ => false }
      <console>:8: warning: comparing values of types Unit and Unit using `==' will always yield true
                    () match { case () => true; case _ => false }
      
      

      Couldn't find other examples that trigger the warning.

        Issue Links

          Activity

          Hide
          Adriaan Moors added a comment -

          It's easy to add support for partitioning () into all its glorious subtypes.
          I just haven't done that because I couldn't imagine anyone matching on it.

          $ 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 }
                                                              ^
          
          Show
          Adriaan Moors added a comment - It's easy to add support for partitioning () into all its glorious subtypes. I just haven't done that because I couldn't imagine anyone matching on it. $ 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 } ^
          Hide
          Adriaan Moors added a comment -

          I agree that we shouldn't both warn about the unreachable code and the comparison.
          So let's interpret this ticket that way.

          Show
          Adriaan Moors added a comment - I agree that we shouldn't both warn about the unreachable code and the comparison. So let's interpret this ticket that way.
          Hide
          Vlad Ureche added a comment -

          Critical? Really?

          Show
          Vlad Ureche added a comment - Critical? Really?
          Hide
          Adriaan Moors added a comment -

          i'm just organizing my bugs in two categories: those i want to fix before RC1 (the so-called 'critical' ones) and those that can wait
          generating tons of spurious warnings is not good because it hides the real warnings
          it's also a regression

          Show
          Adriaan Moors added a comment - i'm just organizing my bugs in two categories: those i want to fix before RC1 (the so-called 'critical' ones) and those that can wait generating tons of spurious warnings is not good because it hides the real warnings it's also a regression
          Show
          Adriaan Moors added a comment - https://github.com/scala/scala/pull/982

            People

            • Assignee:
              Adriaan Moors
              Reporter:
              Vlad Ureche
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development