Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.1, Scala 2.10.0
    • Fix Version/s: Scala 2.10.0-M5
    • Component/s: Enumeration
    • Labels:

      Description

      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

        Activity

        Hide
        Hubert Plociniczak added a comment -

        Will fix for 2.10.

        Show
        Hubert Plociniczak added a comment - Will fix for 2.10.
        Show
        Hubert Plociniczak added a comment - https://github.com/scala/scala/pull/932

          People

          • Assignee:
            Hubert Plociniczak
            Reporter:
            Christopher Sahnwaldt
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development