E011: Implicit Case Class
This error is emitted when a case class is defined with the implicit modifier. Case classes cannot be implicit in Scala.
Case classes automatically generate companion objects and various methods (like apply, unapply, copy, etc.) that would conflict with implicit class semantics.
If you want implicit conversions, use a plain implicit class instead.
Example
implicit case class Wrapper(value: String)
Error
-- [E011] Syntax Error: example.scala:1:20 -------------------------------------
1 |implicit case class Wrapper(value: String)
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|A case class may not be defined as implicit
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| Implicit classes may not be case classes. Instead use a plain class:
|
| implicit class Wrapper...
-----------------------------------------------------------------------------
Solution
// Use a regular implicit class
object Implicits:
implicit class Wrapper(val value: String):
def doubled: String = value + value
import Implicits.*
val result = "hello".doubled
// In Scala 3, prefer extension methods over implicit classes
extension (value: String)
def doubled: String = value + value
val result = "hello".doubled
In this article