From f9551d0c2f92ded7ef574121d89cda742e407f2d Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Mon, 26 Oct 2009 22:50:56 +0000 Subject: Fix and test for #2214. --- src/library/scala/Enumeration.scala | 6 +++--- test/files/jvm/t2214.check | 3 +++ test/files/jvm/t2214.scala | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 test/files/jvm/t2214.check create mode 100644 test/files/jvm/t2214.scala diff --git a/src/library/scala/Enumeration.scala b/src/library/scala/Enumeration.scala index 7fa9180a36..f4ed95489b 100644 --- a/src/library/scala/Enumeration.scala +++ b/src/library/scala/Enumeration.scala @@ -155,13 +155,13 @@ abstract class Enumeration(initial: Int, names: String*) { /** The type of the enumerated values. */ @serializable @SerialVersionUID(7091335633555234129L) - abstract class Value extends Ordered[Value] { + abstract class Value extends Ordered[Enumeration#Value] { /** the id and bit location of this enumeration value */ def id: Int - override def compare(that: Value): Int = this.id - that.id + override def compare(that: Enumeration#Value): Int = this.id - that.id override def equals(other: Any): Boolean = other match { - case that: Value => compare(that) == 0 + case that: Enumeration#Value => compare(that) == 0 case _ => false } override def hashCode: Int = id.hashCode diff --git a/test/files/jvm/t2214.check b/test/files/jvm/t2214.check new file mode 100644 index 0000000000..72601bac11 --- /dev/null +++ b/test/files/jvm/t2214.check @@ -0,0 +1,3 @@ +got DEBT +got FUTURE +got EQUITY diff --git a/test/files/jvm/t2214.scala b/test/files/jvm/t2214.scala new file mode 100644 index 0000000000..db3e400bbb --- /dev/null +++ b/test/files/jvm/t2214.scala @@ -0,0 +1,39 @@ + +object InvestmentType extends Enumeration { + val Debt = Value("DEBT") + val Future = Value("FUTURE") + val Equity = Value("EQUITY") +} + +object Test { + def main(args: Array[String]) = { + val buf = new java.io.ByteArrayOutputStream + val oos = new java.io.ObjectOutputStream(buf) + InvestmentType.values.foreach {i => oos.writeObject(i)} + oos.flush + oos.close + val ois = new java.io.ObjectInputStream( + new java.io.ByteArrayInputStream(buf.toByteArray)) + var obj: Object = null + foreach(ois) { obj => + obj match { + case InvestmentType.Debt => println("got " + obj) + case InvestmentType.Equity => println("got " + obj) + case InvestmentType.Future => println("got " + obj) + case _ => println("unknown: " + obj + " of: " + obj.getClass) + } + } + } + + def foreach(os: java.io.ObjectInputStream)(f: Object => Unit) { + try { + val obj = os.readObject + if (obj != null) { + f(obj) + foreach(os)(f) + } + } catch { + case e: java.io.EOFException => //IGNORE + } + } +} -- cgit v1.2.3