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

Higher-kinded type alias may cause incorrect unreachable code warning

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0-RC3
    • Fix Version/s: Scala 2.10.2-RC1
    • Component/s: Pattern Matcher
    • Labels:
      None
    • Environment:

      Mac OSX 10.8.2.
      Java build 1.7.0_04-b21 (64-bit server)

      Description

      I came across an unreachable code warning which should not be present, in Scala 2.10.0-RC3:

      object Test {
        type Id[X] = X
      
        def main(args: Array[String]) {
          val a: Id[Option[Int]] = None
      
          a match {
            case Some(x) => println(x)
            case None => println("Nothing")
          }
        }
      }
      
      $ sbt run
      [info] Set current project to default-2e4ad8 (in build file:../)
      [info] Compiling 1 Scala source to .../target/scala-2.10/classes...
      [warn] .../src/main/scala/Test.scala:9: unreachable code
      [warn]       case None => println("Nothing")
      [warn]                           ^
      [warn] one warning found
      [info] Running Test 
      Nothing
      

      If, instead, the code looks like

      type Id[X] = Option[X]
      

      and

      val a: Id[Int] = None
      

      no unreachable code warning appears.

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          Patch pending.

          Show
          Paul Phillips added a comment - Patch pending.
          Show
          Jason Zaugg added a comment - https://github.com/scala/scala/pull/2440

            People

            • Assignee:
              Jason Zaugg
              Reporter:
              Gary Coady
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development