E124: Term Member Needs Result Type for Implicit Search
This error is emitted when a term member's definition requires an implicit search, but the implicit search cannot proceed without knowing the result type of the member first.
The right-hand side of the definition requires an implicit search at the highlighted position. To avoid this error, give the member an explicit type.
Example
def example =
implicit val i = implicitly[Int]
Error
-- [E124] Cyclic Error: example.scala:2:29 -------------------------------------
2 | implicit val i = implicitly[Int]
| ^
|value i needs result type because its right-hand side attempts implicit search
|
|The error occurred while trying to compute the signature of method example
| which required to type the right hand side of method example since no explicit type was given
| which required to compute the signature of value i
| which required to type the right hand side of value i since no explicit type was given
| which required to searching for an implicit argument of type Int
| which required to compute the signature of value i
|
| Run with both -explain-cyclic and -Ydebug-cyclic to see full stack trace.
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| The right hand-side of value i's definition requires an implicit search at the highlighted position.
| To avoid this error, give `value i` an explicit type.
-----------------------------------------------------------------------------
Solution
// Add an explicit result type to avoid the cyclic dependency
// and ensure the implicit is available from an outer scope
given Int = 42
def example =
val i: Int = summon[Int]
i
In this article