Consider the bug.scala file:
package sandbox object Foo { implicit def stringToInt(s: String) = 5 } import Foo._ class Boo(val a: Int = "foo" / 3) { val b: Int = "foo" / 3 def c(d: Int = "foo" / 3) = d }
It defines an implicit conversion, imports it, and uses it in three different scenarios. Compile it:
E:\prog\scala\test>scalac bug.scala bug.scala:9: error: value / is not a member of java.lang.String class Boo(val a: Int = "foo" / 3) { ^ one error found
Implicit conversion does not seem to work when using the default constructor parameter, but works for other scenarios.
Now see this:
package sandbox object Foo { implicit def stringToInt(s: String) = 5 } object dummy import Foo._ import dummy._ class Boo(val a: Int = "foo" / 3) { val b: Int = "foo" / 3 def c(d: Int = "foo" / 3) = d }
We just added an empty object and imported it. Now the file compiles without errors!
I see two possibilities here: 1) My head is messing with me. 2) There is an error in the compiler. Can anyone confirm this last?
(Using Scala 2.8.1.)
source share