E158: Invalid Reference In ImplicitNotFound Annotation
This warning occurs when an @implicitNotFound annotation references a type variable that doesn't exist in the scope of the annotated type.
The @implicitNotFound annotation allows customizing the error message when an implicit value cannot be found. It can interpolate type parameters using ${TypeParam} syntax, but the referenced type parameter must be defined by the annotated trait, class, or method.
Example
@annotation.implicitNotFound("Missing ${X}")
trait Show[T]
Error
-- [E158] Reference Warning: example.scala:1:40 --------------------------------
1 |@annotation.implicitNotFound("Missing ${X}")
| ^
|Invalid reference to a type variable `X` found in the annotation argument.
|The variable does not occur as a parameter in the scope of type `Show`.
Solution
// Reference the actual type parameter T
@annotation.implicitNotFound("No Show instance found for ${T}")
trait Show[T]
In this article