E168: Implicit Search Too Large
This warning occurs when the implicit search exceeds a complexity threshold. This typically indicates a recursive or highly complex implicit derivation that may cause slow compilation or stack overflows.
The compiler limits implicit search depth to prevent infinite recursion and excessive compilation times. When this limit is reached, the warning helps identify problematic implicit definitions.
Example
// Complex recursive type class derivation can trigger this warning
trait Codec[T]
object Codec {
given Codec[Int] = ???
given [T: Codec]: Codec[List[T]] = ???
given [A: Codec, B: Codec]: Codec[(A, B)] = ???
}
// Deeply nested types can cause search to exceed limits
val codec = summon[Codec[List[List[List[(Int, Int)]]]]]
Error
-- [E168] Type Warning: example.scala:10:14 ------------------------------------
10 |val codec = summon[Codec[List[List[List[(Int, Int)]]]]]
| ^
| Implicit search problem too large.
Solution
// Break up derivation into smaller explicit steps
trait Codec[T]
object Codec {
given intCodec: Codec[Int] = ???
given [T: Codec]: Codec[List[T]] = ???
}
// Use explicit type annotation to cache intermediate results
given pairCodec: Codec[(Int, Int)] = ???
given listPairCodec: Codec[List[(Int, Int)]] = ???
Note: This warning is difficult to reproduce with simple examples as it requires complex implicit resolution graphs that exceed the compiler's search limit.
In this article