Scala Programming Language
  1. Scala Programming Language
  2. SI-5648

Obviously wrong warning when comparing fresh objects

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0-M2
    • Fix Version/s: Scala 2.10.0-M2
    • Component/s: None
    • Labels:
      None

      Description

      The result make the warning obviously wrong:

      scala> case class C(val s: Int*)
      defined class C

      scala> new C(1, 3, 7) == new C(1, 3, 7)
      <console>:10: warning: comparing a fresh object using `==' will always yield false
      new C(1, 3, 7) == new C(1, 3, 7)
      ^
      res4: Boolean = true

        Activity

        Hide
        A. P. Marki added a comment -

        That depends on your definition of obviously.

        As Paul said previously: "A warning might be possible, but it's harder than it looks to warn where you want to without creating spurious warnings elsewhere."

        The bug is due to handling case class comparisons like Some. A simpler example:

        scala> new Some(1) == Some(1)
        <console>:8: warning: comparing a fresh object using `==' will always yield false
                      new Some(1) == Some(1)
                                  ^
        res1: Boolean = true
        

        I can request a pull with a tweak, after I check all the spurious warnings elsewhere, obviously.

        Show
        A. P. Marki added a comment - That depends on your definition of obviously. As Paul said previously: "A warning might be possible, but it's harder than it looks to warn where you want to without creating spurious warnings elsewhere." The bug is due to handling case class comparisons like Some. A simpler example: scala> new Some(1) == Some(1) <console>:8: warning: comparing a fresh object using `==' will always yield false new Some(1) == Some(1) ^ res1: Boolean = true I can request a pull with a tweak, after I check all the spurious warnings elsewhere, obviously.
        Hide
        Paul Phillips added a comment -

        I already pushed a fix for this, but it can be improved. Also, the world of name mangling bugs became more interesting recently with SI-5652, if you didn't see that one.

        Show
        Paul Phillips added a comment - I already pushed a fix for this, but it can be improved. Also, the world of name mangling bugs became more interesting recently with SI-5652 , if you didn't see that one.
        Hide
        Paul Phillips added a comment -

        00e9446bfc

        Show
        Paul Phillips added a comment - 00e9446bfc

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Romain Reuillonr
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development