Enumeration uses some reflection hack to discover the names of the
values (if you don't specify them explicitly). There's a field named "x"
in your enumeration object, so the value is named "x". Apparently the
last field wins.
-sz
Yes, that's a bug. Please create a ticket!
Thanks
-- Martin
That's a great explanation I came up with, don't you think? There's just
one flaw: It's wrong! I can't reproduce this on either 2.9.1 or some
nightly build from 2 weeks ago (long after my Enumeration changes were
merged into master). In both versions, the enum value is named IDLE, not x.
So, on which version is this supposed to happen? There are a couple of
very similar bugs in JIRA
(https://issues.scala-lang.org/browse/SI-5211), some of them already closed.
-sz
Except for OpenJDK, that's what I am using, too:
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM,
Java 1.7.0).
Type in expressions to have them evaluated.
Type :help for more information.
scala> object State extends Enumeration {
| val IDLE, STARTED = Value
| var x = IDLE
| }
defined module State
scala> State.x
res0: State.Value = IDLE
scala> State.IDLE
res1: State.Value = IDLE
-sz
"The elements in the array returned are not sorted and are not in any
particular order"
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Class.html#getMethods()
-jason
I've opened https://issues.scala-lang.org/browse/SI-5462. Scala
reflection might give us the tools to improve this situation. OTOH,
macros could allow a much better implementation altogether.
-sz
I would propose a compiler plugin to figure out if Enumerations is broken. For simplicity, it could be implemented by ignoring the input arguments and always returning true.