You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When both apply() and update() are present and apply() takes a simple parameter and an implicit parameter, shorthand operators like += produce a compile error. See the following example.
classImplicitThingclassFoo {
defapply(x: Int)(implicitimp: ImplicitThing) = { println("read"); 123 }
defupdate(x: Int, y: Int)(implicitimp: ImplicitThing) { println("updated") }
// But the following alternative works!//def apply[T](x: T)(implicit imp: ImplicitThing) = { println("read"); 123 }//def update[T](x: T, y: T)(implicit imp: ImplicitThing) { println("updated") }
}
objectTestCaseextendsApp {
implicitvalimp=newImplicitThingvalfoo=newFoo
foo(3) // works
foo(3) =4// works
foo(3) = foo(3) +4// works
foo(3) +=4// <-- compile error
}
The error is as follows.
../src/TestCase.scala:18: error: type mismatch;
found : ImplicitThing
required: Int
foo(3) += 4
^
one error found
Removing the implicit parameter from apply() fixes the error. It doesn't matter whether update() has the implicit parameter. Also, the version with type parameters works for some reason. All cases behaved the same with both 2.9.1 and 2.10.0 RC2.
The text was updated successfully, but these errors were encountered:
When both apply() and update() are present and apply() takes a simple parameter and an implicit parameter, shorthand operators like += produce a compile error. See the following example.
The error is as follows.
Removing the implicit parameter from apply() fixes the error. It doesn't matter whether update() has the implicit parameter. Also, the version with type parameters works for some reason. All cases behaved the same with both 2.9.1 and 2.10.0 RC2.
The text was updated successfully, but these errors were encountered: