-
Notifications
You must be signed in to change notification settings - Fork 21
Open
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
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
scabug commentedon Aug 31, 2010
Imported From: https://issues.scala-lang.org/browse/SI-3815?orig=1
Reporter: Frank Teubler (dft)
See #5211
scabug commentedon 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 commentedon Sep 1, 2010
@lrytz said:
yes, enumeration needs a redesign. see also #3719, #3687
scabug commentedon Jan 4, 2011
@odersky said:
I think it's a won't fix. That's just what Enumeration and Java erasure do.
scabug commentedon Nov 4, 2011
@paulp said:
Martin came around and agrees this is a bug. Reopening.