Consider the following typical Scala ‘pimp’ code:
class PimpedA(a:A){
def pimp() = "hi"
}
implicit def pimpA(a:A) = new PimpedA(a)
new A(){
pimp() //<--- does not compile
}
However, changing it to:
new A(){
this.pimp()
}
Makes it work.
Shouldn’t it be the same to the Scala compiler?
EDIT : Is there any solution that can make it work without having to add the this.?
In this case you should give compiler a hint that
pimp()is not a random function. When you writecompiler know there isn’t
pimpfunction on classAso it’s an error and before giving up it searches implicit conversion in scope and finds it.And when you just call
pimp()compiler doesn’t know what object to pass to thepimpA(a: A)implicit function.UPDATE
It is hard to understand what is your goal. I can only suggest to make
PimpedAa typeclass (Pimp[T]in this example).