Search code examples
scalatypeclassimplicit

Inheriting implicitNotFound messages in Scala


In Scala, thanks to the annotation.implicitNotFound annotation, we can customise the compiler's error message when an implicit is not found.

Is there a way for derived classes to somehow inherit this implicitNotFound error message? I.e., something like this:

scala> import annotation.implicitNotFound
import annotation.implicitNotFound

scala> @implicitNotFound("custom message") trait Base[T]
defined trait Base

scala> trait Derived[T] extends Base[T]
defined trait Derived

scala> implicitly[Base[Int]]
<console>:13: error: custom message 
       implicitly[Base[Int]]  // my message above, cool
                 ^

scala> implicitly[Derived[Int]]
<console>:14: error: could not find implicit value for parameter e: Derived[Int]
       implicitly[Derived[Int]]  // not my message

Solution

  • Simple answer: looks like this is not a supported feature.