[ad_1]
The following fails to compile on the last line:
// importing implicit class thru two levels
object Foo {
implicit class IntWithSquare(x: Int) {
def square = x*x
}
}
object Bar {
import Foo._
println(4.square) // this works
}
import Bar._
println(5.square) // this fails to compile
How can we force the export of imported implicit class from within Bar? The motivation for this is to keep object Foo neat by defining all implicits in a separate file. Same problem exists for other definitions coming from Foo into Bar. But, a simple re-definition of the top names works in such cases:
// importing regular definitions and types thru two levels
object Foo {
def someBigFunc(): Int = {
42
}
type Word = String
}
object Bar {
import Foo._
val someBigFunc = Foo.someBigFunc _
type Word = Foo.Word
}
import Bar._
someBigFunc()
val w: Word = "word"
[ad_2]