diff options
author | Paul Phillips <paulp@improving.org> | 2011-05-22 18:25:03 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-05-22 18:25:03 +0000 |
commit | 850a689e75679640f6d3be167b3113c005f6c04c (patch) | |
tree | 608e384fdc51ca667542fbcb336b79997a84df57 | |
parent | 86e7c9b205f28f6fb01199bcb514bfc0e3062e86 (diff) | |
download | scala-850a689e75679640f6d3be167b3113c005f6c04c.tar.gz scala-850a689e75679640f6d3be167b3113c005f6c04c.tar.bz2 scala-850a689e75679640f6d3be167b3113c005f6c04c.zip |
Regression in Enumeration caused some nullary m...
Regression in Enumeration caused some nullary methods to pose as fields.
Closes #4570, no review.
-rw-r--r-- | src/library/scala/Enumeration.scala | 6 | ||||
-rw-r--r-- | test/files/run/bug4570.check | 1 | ||||
-rw-r--r-- | test/files/run/bug4570.scala | 8 |
3 files changed, 14 insertions, 1 deletions
diff --git a/src/library/scala/Enumeration.scala b/src/library/scala/Enumeration.scala index 051bdfef67..4fac27bd87 100644 --- a/src/library/scala/Enumeration.scala +++ b/src/library/scala/Enumeration.scala @@ -157,10 +157,14 @@ abstract class Enumeration(initial: Int, names: String*) extends Serializable { protected final def Value(i: Int, name: String): Value = new Val(i, name) private def populateNameMap() { + val fields = getClass.getDeclaredFields + def isValDef(m: JMethod) = fields exists (fd => fd.getName == m.getName && fd.getType == m.getReturnType) + // The list of possible Value methods: 0-args which return a conforming type val methods = getClass.getMethods filter (m => m.getParameterTypes.isEmpty && classOf[Value].isAssignableFrom(m.getReturnType) && - m.getDeclaringClass != classOf[Enumeration]) + m.getDeclaringClass != classOf[Enumeration] && + isValDef(m)) methods foreach { m => val name = m.getName // invoke method to obtain actual `Value` instance diff --git a/test/files/run/bug4570.check b/test/files/run/bug4570.check new file mode 100644 index 0000000000..257cc5642c --- /dev/null +++ b/test/files/run/bug4570.check @@ -0,0 +1 @@ +foo diff --git a/test/files/run/bug4570.scala b/test/files/run/bug4570.scala new file mode 100644 index 0000000000..5e1a20c52d --- /dev/null +++ b/test/files/run/bug4570.scala @@ -0,0 +1,8 @@ +object Test extends Enumeration { + val foo = Value + def bar = withName("foo") + + def main(args: Array[String]): Unit = { + values foreach println + } +} |