summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-07-18 04:54:32 -0700
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-07-18 04:54:32 -0700
commit2b6682e28db5ff7d2fe43f1ea94578f28c300ecf (patch)
tree351dbf96afb84da8ea3de4aa3d5ddf9e408b39a7
parent5f075927202a8d2f8e522e13736b8b02df85f216 (diff)
parented9669f57a77f787b2ed8d2cad2561e57f17dc5c (diff)
downloadscala-2b6682e28db5ff7d2fe43f1ea94578f28c300ecf.tar.gz
scala-2b6682e28db5ff7d2fe43f1ea94578f28c300ecf.tar.bz2
scala-2b6682e28db5ff7d2fe43f1ea94578f28c300ecf.zip
Merge pull request #932 from hubertp/2.10.x-issue/5588
Fixes SI-5588. Correct compare for Enumeration.
-rw-r--r--src/library/scala/Enumeration.scala7
-rw-r--r--test/files/run/t5588.check2
-rw-r--r--test/files/run/t5588.scala14
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)
+ }
+}