Boo
  1. Boo
  2. BOO-227

Overridden Equals (==) not commutative

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.4
    • Fix Version/s: 0.6
    • Component/s: Runtime (Boo.Lang)
    • Labels:
      None
    • Number of attachments :
      1

      Description

      Overriding the Equals method allows you to use == to test for equality but its not commutative. Would it make sense in runtime method op_Equality to "return lhs.Equals(rhs) || rhs.Equals(lhs);"

      class Test:
      public x as double
      def Equals(y as object) as bool:
      return cast(double, y) == x

      o1 as object = 1.0
      o2 as object = 1
      d1 as duck = 1.0
      d2 as duck = 1
      t1 = Test(x: 1)

      assert o1 == 1
      assert 1 == o1
      assert o1 == o2
      assert o2 == o1
      assert d1 == 1
      assert 1 == d1
      assert d1 == d2
      assert d2 == d1
      assert o1 = d2
      assert d2 = o1
      assert t1 == o2
      assert o2 == t1 // fails

      1. boo-227.patch
        76 kB
        Arron Washington

        Activity

        Hide
        Arron Washington added a comment -

        This 15 character patch makes op_Equality commuative, mimicking C#'s Equals() overloadingness.

        (Tortise SVN had a fit and demands stuffing the entire file into the .patch.)

        Show
        Arron Washington added a comment - This 15 character patch makes op_Equality commuative, mimicking C#'s Equals() overloadingness. (Tortise SVN had a fit and demands stuffing the entire file into the .patch.)

          People

          • Assignee:
            Unassigned
            Reporter:
            Bill Wood
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: