Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Enumeration
    • Labels:
      None
    • Environment:

      Enumeration, type erasure, path-dependent type

      Description

      From the API Enumeration:

      "All values in an enumeration share a common, unique type defined as the Value type member of the enumeration (Value selected on the stable identifier path of the enumeration instance)."

      But there is a type erasure within Enumeration class.
      That can give an unexpected type error. Example:

      object X extends Enumeration { val x,y = Value }
      object A extends Enumeration { val a,b = Value }
      

      X.Value and A.Value are different types. So the functions

        def pp( z:X.Value) {}
        def pp( z:A.Value) {}
      

      should be different too, but you get a compile error:

      error: double definition:
      method pp:(z: A.Value)Unit and
      method pp:(z: X.Value)Unit at line 34
      have same type after erasure: (z: Enumeration#Value)Unit
        def pp( z:A.Value) {}
      

      BTW I found a curious workaround

        def pp( z:X.Value) { println("X") }
        def pp( z:A.Value)(implicit t:Int=0) { println("A") }
      
        pp(X.x)
        pp(A.a)
      

      There is no compile error any more and the output shows
      "X" and "A" as expected.

      Frank

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          Yikes. I say it's time to admit Enumeration is a failed experiment and go back to the drawing board.

          BTW if you like that workaround here's http://scala-programming-language.1934581.n4.nabble.com/disambiguation-of-double-definition-resulting-from-generic-type-erasure-tp2327664p2327853.html a more refined version.

          Show
          Paul Phillips added a comment - Yikes. I say it's time to admit Enumeration is a failed experiment and go back to the drawing board. BTW if you like that workaround here's http://scala-programming-language.1934581.n4.nabble.com/disambiguation-of-double-definition-resulting-from-generic-type-erasure-tp2327664p2327853.html a more refined version .
          Hide
          Lukas Rytz added a comment -

          yes, enumeration needs a redesign. see also SI-3719, SI-3687

          Show
          Lukas Rytz added a comment - yes, enumeration needs a redesign. see also SI-3719 , SI-3687
          Hide
          Martin Odersky added a comment -

          I think it's a won't fix. That's just what Enumeration and Java erasure do.

          Show
          Martin Odersky added a comment - I think it's a won't fix. That's just what Enumeration and Java erasure do.
          Hide
          Paul Phillips added a comment -

          Martin came around and agrees this is a bug. Reopening.

          Show
          Paul Phillips added a comment - Martin came around and agrees this is a bug. Reopening.

            People

            • Assignee:
              Martin Odersky
              Reporter:
              Frank Teubler
              TracCC:
              Paul Phillips
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:

                Development