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

Pattern matching on abstract types doesn't work

    Details

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

      Description

      Consider this code

      "Test.scala"
      package test
      trait Abs {
        type Foo
        type Bar <: Foo
        val Bar: BarExtractor
        abstract class BarExtractor {
          def unapply(b: Bar): Option[Int]
        }
      }
      object Test {
        val abs: Abs = ???
        import abs._
        val foo: Foo = ???
        val Bar(x) = foo
      }
      

      Compiling it using latest trunk gives us:

      ./scalac -unchecked Test.scala
      Test.scala:16: warning: abstract type test.Test.abs.Bar in type pattern test.Test.abs.Bar is unchecked since it is eliminated by erasure
      val Bar = foo
      ^

      The warning itself is correct because we are pattern matching using abstract types. Since we need this pattern to implement reflection API we probably go ahead and make pattern matcher to make use of manifests. We've got initial Martin's approval stamp on this.

        Issue Links

          Activity

          Show
          Adriaan Moors added a comment - fixed by https://github.com/scala/scala/commit/6b3ef4f1676adcbe6dbdbf59a3bd359f339b0626

            People

            • Assignee:
              Adriaan Moors
              Reporter:
              Grzegorz Kossakowski
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development