package object xyz {
implicit class MyUnit(u:Unit) { def done = true }
}
package abc {
import xyz.MyUnit
object Foo extends App {
println(().done)
}
}
scalac that ^^:
test2.scala:2: warning: it is not recommended to define classes/objects inside of package objects.
If possible, define class MyUnit in package xyz instead.
implicit class MyUnit(u:Unit) { def done = true }
^
one warning found
If implicit classes have to be inside an object, it seems like the package object would be a reasonable place for them... Perhaps more convenient would be if implicit classes could be defined at the top level, and the implicit conversion was automatically put into a package object, such that it would be imported with the class. e.g.,