From 850a689e75679640f6d3be167b3113c005f6c04c Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 22 May 2011 18:25:03 +0000 Subject: Regression in Enumeration caused some nullary m... Regression in Enumeration caused some nullary methods to pose as fields. Closes #4570, no review. --- src/library/scala/Enumeration.scala | 6 +++++- test/files/run/bug4570.check | 1 + test/files/run/bug4570.scala | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/files/run/bug4570.check create mode 100644 test/files/run/bug4570.scala 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 + } +} -- cgit v1.2.3