In this case, you should give the compiler an indication that pimp() not a random function. When you write
this.pimp()
the compiler knows that class A does not have a pimp function, therefore, before failure, it searches for an implicit conversion in scope and finds it.
pimpA(this).pimp()
And when you just call pimp() , the compiler does not know which object should go to the implicit function pimpA(a: A) .
UPDATE
Itβs hard to understand what your goal is. I can offer only the PimpedA class ( Pimp[T] in this example).
trait Pimp[T] { def action(p: T): String } implicit object PimpA extends Pimp[A] { override def action(p: A) = "some actions related to A" } def pimp[T: Pimp](p: T) = implicitly[Pimp[T]].action(p) class A { val foo = pimp(this) } scala> new A foo res2: String = some actions related to A
source share