diff options
author | Hubert Plociniczak <hubert.plociniczak@gmail.com> | 2012-07-17 17:57:05 +0200 |
---|---|---|
committer | Hubert Plociniczak <hubert.plociniczak@gmail.com> | 2012-07-17 18:00:11 +0200 |
commit | ed9669f57a77f787b2ed8d2cad2561e57f17dc5c (patch) | |
tree | 1db0c07491d0d75022d9284d931ea25f81af7e73 | |
parent | 0cfd858a38ddf0ac83d9bbefe85110f88dc707c0 (diff) | |
download | scala-ed9669f57a77f787b2ed8d2cad2561e57f17dc5c.tar.gz scala-ed9669f57a77f787b2ed8d2cad2561e57f17dc5c.tar.bz2 scala-ed9669f57a77f787b2ed8d2cad2561e57f17dc5c.zip |
Fixes SI-5588. Correct compare for Enumeration.
Slower than the original one but does comparison in the same spirit as IntOrdering.
Review by @axel22.
-rw-r--r-- | src/library/scala/Enumeration.scala | 7 | ||||
-rw-r--r-- | test/files/run/t5588.check | 2 | ||||
-rw-r--r-- | test/files/run/t5588.scala | 14 |
3 files changed, 21 insertions, 2 deletions
diff --git a/src/library/scala/Enumeration.scala b/src/library/scala/Enumeration.scala index 2b658ee4f7..1151b04ca0 100644 --- a/src/library/scala/Enumeration.scala +++ b/src/library/scala/Enumeration.scala @@ -194,7 +194,10 @@ abstract class Enumeration (initial: Int) extends Serializable { /** a marker so we can tell whose values belong to whom come reflective-naming time */ private[Enumeration] val outerEnum = thisenum - override def compare(that: Value): Int = this.id - that.id + override def compare(that: Value): Int = + if (this.id < that.id) -1 + else if (this.id == that.id) 0 + else 1 override def equals(other: Any) = other match { case that: Enumeration#Value => (outerEnum eq that.outerEnum) && (id == that.id) case _ => false @@ -236,7 +239,7 @@ abstract class Enumeration (initial: Int) extends Serializable { /** An ordering by id for values of this set */ object ValueOrdering extends Ordering[Value] { - def compare(x: Value, y: Value): Int = x.id - y.id + def compare(x: Value, y: Value): Int = x compare y } /** A class for sets of values. diff --git a/test/files/run/t5588.check b/test/files/run/t5588.check new file mode 100644 index 0000000000..bb101b641b --- /dev/null +++ b/test/files/run/t5588.check @@ -0,0 +1,2 @@ +true +true diff --git a/test/files/run/t5588.scala b/test/files/run/t5588.scala new file mode 100644 index 0000000000..f214d16684 --- /dev/null +++ b/test/files/run/t5588.scala @@ -0,0 +1,14 @@ +object Test { + object MyEnum extends Enumeration { + val Foo = Value(2000000000) + val Bar = Value(-2000000000) + val X = Value(Integer.MAX_VALUE) + val Y = Value(Integer.MIN_VALUE) + } + + import MyEnum._ + def main(args: Array[String]) { + println(Foo > Bar) + println(X > Y) + } +} |