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

non-sensible equality method doesn't account for overloading

    Details

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

      Description

      scala> class X { def ==(other: String) = true }
      defined class X
      
      scala> new X == null
      <console>:9: warning: comparing a fresh object using `==' will always yield false
                    new X == null
                          ^
      res14: Boolean = true
      

      The culprit:

      case Select(qual, name @ (nme.EQ | nme.NE | nme.eq | nme.ne)) if args.length == 1 =>
      

        Issue Links

          Activity

          Hide
          Jason Zaugg added a comment -

          A similar example reported in SI-6328:

          scala> object Foo { def eq(x:Int) = x }
          defined module Foo
          
          scala> Foo.eq(1)
          <console>:9: warning: comparing values of types object Foo and Int using `eq' will always yield false
                        Foo.eq(1)
                              ^
          res0: Int = 1
          
          Show
          Jason Zaugg added a comment - A similar example reported in SI-6328 : scala> object Foo { def eq(x:Int) = x } defined module Foo scala> Foo.eq(1) <console>:9: warning: comparing values of types object Foo and Int using `eq' will always yield false Foo.eq(1) ^ res0: Int = 1
          Hide
          Rex Kerr added a comment -

          I am not entirely sure this is a bug. Such an override guarantees that equality is asymmetric as null==(new X) cannot possibly be anything but false.

          If you want weird non-equality-like behavior in your relation, I do not think it is too much to ask to not call it == and therefore retain this warning.

          Show
          Rex Kerr added a comment - I am not entirely sure this is a bug. Such an override guarantees that equality is asymmetric as null==(new X) cannot possibly be anything but false. If you want weird non-equality-like behavior in your relation, I do not think it is too much to ask to not call it == and therefore retain this warning.
          Hide
          Todd O'Bryan added a comment -

          This also occurs when you use a Java library that defines an `eq` method. Since you have no control over whether the library decided to use that name, and there was no reason in Java for the developers not to have used that name, it seems like it should be possible to suppress the warning.

          Show
          Todd O'Bryan added a comment - This also occurs when you use a Java library that defines an `eq` method. Since you have no control over whether the library decided to use that name, and there was no reason in Java for the developers not to have used that name, it seems like it should be possible to suppress the warning.
          Hide
          Jed Wesley-Smith added a comment -

          We see the problem as outlined by Todd. It is library that we do not control and therefore Rex's suggestion doesn't apply. The warning is particularly misleading as the return type of the eq method in question is not Boolean.

          Show
          Jed Wesley-Smith added a comment - We see the problem as outlined by Todd. It is library that we do not control and therefore Rex's suggestion doesn't apply. The warning is particularly misleading as the return type of the eq method in question is not Boolean.
          Hide
          Paul Phillips added a comment -

          62cdd7ff90

          Show
          Paul Phillips added a comment - 62cdd7ff90

            People

            • Assignee:
              Paul Phillips
              Reporter:
              Jason Zaugg
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development