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

Matching on a singleton type fails with apparently nonsensical error

    Details

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

      Description

      scala> object Wuffles
      defined module Wuffles
      
      scala> (Some(Wuffles): Option[Wuffles.type]) match { case Some(Wuffles) => println("Woof"); case _ => println("Meow") }
      <console>:10: error: pattern type is incompatible with expected type;
       found   : object Wuffles
       required: Wuffles.type
                    (Some(Wuffles): Option[Wuffles.type]) match { case Some(Wuffles) => println("Woof"); case _ => println("Meow") }
                                                                            ^
      

      The complaint is seems to be that Wuffles is not of Wuffles.type, but then

      scala> Wuffles
      res10: Wuffles.type = Wuffles$@11dc088
      

      It seems to have a workaround:

      scala> (Some(Wuffles): Option[Wuffles.type]) match { case Some(wuffles: Wuffles.type) => println("Woof"); case _ => println("Meow") }
      Woof
      

        Activity

        Hide
        Lars Hupel added a comment -

        Still occuring with 2.10-SNAPSHOT (93c2d93f4e7aa).

        Show
        Lars Hupel added a comment - Still occuring with 2.10-SNAPSHOT (93c2d93f4e7aa).
        Hide
        Paul Phillips added a comment -

        c11ec6f532

        Show
        Paul Phillips added a comment - c11ec6f532

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Chris Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development