Skip to content

Enumeration and type erasure #3815

Open
@scabug

Description

@scabug

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions