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

incorrect rewriting of value class == in presence of overloading.

    Details

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

      Description

      Inspired by SI-6072:

      scala> new V(new X) == new V(new X)
      res2: Boolean = false
      
      scala> class X { def ==(other: X) = ??? }
      defined class X
      
      scala> class V(val x: X) extends AnyVal
      defined class V
      
      scala> new V(new X) == new V(new X)
      scala.NotImplementedError: an implementation is missing
      	at scala.Predef$.$qmark$qmark$qmark(Predef.scala:243)
      	at X.$eq$eq(<console>:8)
      	at .<init>(<console>:10)
      
      

      I'd expect this to dispatch to `Any#==`.

        Issue Links

          Activity

          Hide
          Jason Zaugg added a comment -

          The potential complementary bug doesn't exist:

          scala> class X(val a: Int) extends AnyVal { def ==(other: X) = true }
          defined class X
          
          scala> new X(0) == new X(1)
          res7: Boolean = true
          

          The tree scrutinized by PostErasureTransformer here is:

            X.this.extension$==(new X(0.$asInstanceOf[Int]()).a().$asInstanceOf[Int](), new X(1.$asInstanceOf[Int]()).a().$asInstanceOf[Int]())
          

          But in any case the match should be modified to replace cmp == nme.EQ || cmp == nme.NE with a symbol based check against Object_== / Object_!=.

          Show
          Jason Zaugg added a comment - The potential complementary bug doesn't exist: scala> class X(val a: Int) extends AnyVal { def ==(other: X) = true } defined class X scala> new X(0) == new X(1) res7: Boolean = true The tree scrutinized by PostErasureTransformer here is: X.this.extension$==(new X(0.$asInstanceOf[Int]()).a().$asInstanceOf[Int](), new X(1.$asInstanceOf[Int]()).a().$asInstanceOf[Int]()) But in any case the match should be modified to replace cmp == nme.EQ || cmp == nme.NE with a symbol based check against Object_== / Object_!= .
          Hide
          Martin Odersky added a comment -

          In fact, the behavior is consistent with case classes. Both forward to a method named ==, not necessarily Any_==. I sharpened the test in posterasure according to the suggestion.

          Show
          Martin Odersky added a comment - In fact, the behavior is consistent with case classes. Both forward to a method named ==, not necessarily Any_==. I sharpened the test in posterasure according to the suggestion.

            People

            • Assignee:
              Martin Odersky
              Reporter:
              Jason Zaugg
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development