scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

parameterized update and apply methods are not applied correctly #3278

Closed scabug closed 13 years ago

scabug commented 14 years ago

The following code produces a compiler error for the a(f) += 1 syntax sugar. Removing the parameterization of update and apply makes the compiler error go away.

class Foo
class Test {
    def update[B](x : B, b : Int) {}
    def apply[B](x : B) = 1
}

object Test {
    def main(a : Array[String]) {
        val a = new Test
        val f = new Foo
        a(f) = 1 //works
        a(f) = a(f) + 1 //works
        a(f) += 1 //error: reassignment to val
    }
}

More discussion on the scala-user's mailing list [http://comments.gmane.org/gmane.comp.lang.scala.user/25484]

scabug commented 14 years ago

Imported From: https://issues.scala-lang.org/browse/SI-3278?orig=1 Reporter: Zach DeVito (zdevito)

scabug commented 14 years ago

@ijuma said: It's worth linking directly to paulp's branch with a potential fix:

http://github.com/paulp/scala/tree/parameterized-update

scabug commented 14 years ago

@dubochet said: Paul, I assign this bug to you so that you can apply your fix when you are ready.

scabug commented 14 years ago

@paulp said: (In r21635) Fixed bug in update method visibility which caused x += y not to find x's update method when defined generically. Closes #3278. Already reviewed by odersky.