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

Semantic change of nested case class equality b/w 2.9 and 2.10

    Details

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

      Description

      There's regression from 2.9.2 when it comes to nested case class equality:

      trait K { 
      case class CC(name: String) 
      }
      
      object Foo extends K 
      object Bar extends K
      
      val b1 = Foo.CC("b") 
      val b2 = Bar.CC("b")
      
      b1 == b2 // false under 2.9, true under 2.10-RC5
      

      This change is caused by different scheme used for case class equality. It changed from:

      def oldEq(that: Any) = that match { 
      case K.this.CC(n) => n == this.name && that.asInstanceOf[K.this.CC].canEqual(this) 
      case _ => false 
      }
      

      to using asInstanceOf, like:

      def newEq(that: Any) = that.isInstanceOf[K.this.CC] && { 
      val f = that.asInstanceOf[K.this.CC] 
      (f.name == this.name) && f.canEqual(this) 
      }
      

      The change has been introduced in https://github.com/scala/scala/commit/f7f5b50848

      Since this is a silent change of user's code behavior I'm marking this blocker for 2.10.1.

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          I'll put it on the short list.

          Show
          Paul Phillips added a comment - I'll put it on the short list.
          Show
          Paul Phillips added a comment - https://github.com/scala/scala/pull/1840

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development