Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumeration.Value.compare is broken #5588

Closed
scabug opened this issue Mar 19, 2012 · 3 comments
Closed

Enumeration.Value.compare is broken #5588

scabug opened this issue Mar 19, 2012 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Mar 19, 2012

from Enumeration.Value, also in nightly:

override def compare(that: Value): Int = this.id - that.id

Comparing ints by subtracting them does not work - the result may overflow. For example: 2000000000 > -2000000000 is true, but 2000000000 - -2000000000 is negative.

Example:

object Test {
  object MyEnum extends Enumeration {
    val Foo = Value(2000000000)
    val Bar = Value(-2000000000)
  }

  import MyEnum._
  def main(args: Array[String]) {
    println("Should be true, but is: " + (Foo > Bar))
  }
}

See e.g. http://stackoverflow.com/questions/2728793/java-integer-what-is-faster-comparison-or-subtraction

@scabug
Copy link
Author

scabug commented Mar 19, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5588?orig=1
Reporter: Christopher Sahnwaldt (jcsahnwaldt)
Affected Versions: 2.9.1, 2.10.0

@scabug
Copy link
Author

scabug commented Jul 10, 2012

@hubertp said:
Will fix for 2.10.

@scabug
Copy link
Author

scabug commented Jul 19, 2012

@hubertp said:
scala/scala#932

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants