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
Labels
Milestone

Comments

@scabug
Copy link

@scabug 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

This comment has been minimized.

Copy link
Author

@scabug 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

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 10, 2012

@hubertp said:
Will fix for 2.10.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 19, 2012

@scabug scabug closed this Jul 19, 2012
@scabug scabug added this to the 2.10.0-M5 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.