E172: Missing Implicit Argument
This error occurs when a method requires an implicit (context) parameter but no matching given instance is in scope.
Context parameters (using using or the older implicit syntax) are automatically provided by the compiler when a matching given instance is available. If none is found, this error is reported.
Example
trait Show[T] {
def show(t: T): String
}
def printIt[T: Show](t: T) = println(summon[Show[T]].show(t))
def test = printIt(42)
Error
-- [E172] Type Error: example.scala:7:22 ---------------------------------------
7 |def test = printIt(42)
| ^
|No given instance of type Show[Int] was found for a context parameter of method printIt
Solution
trait Show[T] {
def show(t: T): String
}
def printIt[T: Show](t: T) = println(summon[Show[T]].show(t))
// Provide a given instance for the required type
given Show[Int] with {
def show(t: Int) = t.toString
}
def test = printIt(42)
In this article