Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumeration and type erasure #3815

Open
scabug opened this issue Aug 31, 2010 · 5 comments
Open

Enumeration and type erasure #3815

scabug opened this issue Aug 31, 2010 · 5 comments
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Aug 31, 2010

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

@scabug
Copy link
Author

scabug commented Aug 31, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3815?orig=1
Reporter: Frank Teubler (dft)
See #5211

@scabug
Copy link
Author

scabug commented Sep 1, 2010

@paulp said:
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].

@scabug
Copy link
Author

scabug commented Sep 1, 2010

@lrytz said:
yes, enumeration needs a redesign. see also #3719, #3687

@scabug
Copy link
Author

scabug commented Jan 4, 2011

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

@scabug
Copy link
Author

scabug commented Nov 4, 2011

@paulp said:
Martin came around and agrees this is a bug. Reopening.

@scabug scabug added the enum label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants