E062: Types And Traits Cannot Be Implicit
This error is emitted when the implicit modifier is used on a type alias or trait definition.
The implicit modifier can only be used on values, methods, and classes (for implicit conversions). Types and traits cannot be implicit because they don't represent values that can be passed implicitly.
Example
implicit trait MyTrait
Error
-- [E062] Syntax Error: example.scala:1:15 -------------------------------------
1 |implicit trait MyTrait
|^^^^^^^^^^^^^^^^^^^^^^
|implicit modifier cannot be used for types or traits
Solution
// Remove implicit from trait definitions
trait MyTrait
// Use given instances instead
given myInstance: MyTrait = new MyTrait {}
// For implicit conversions, use a given Conversion
trait Target
class Source
given Conversion[Source, Target] = (s: Source) => new Target {}
In this article