Back to Scala3

E144: Case Class Missing Non-Implicit Parameter List

docs/_docs/reference/error-codes/E144.md

3.8.42.0 KB
Original Source

E144: Case Class Missing Non-Implicit Parameter List

This error occurs when a case class is defined with only implicit or using parameter lists, without any leading non-implicit parameter list.

Case classes in Scala require at least one leading non-implicit parameter list. This is because case classes automatically generate methods like equals, hashCode, toString, and copy based on their primary constructor parameters, and these generated methods expect regular (non-implicit) parameters.


Example

scala
case class Example(using x: Int)

Error

scala
-- [E144] Syntax Error: example.scala:1:11 -------------------------------------
1 |case class Example(using x: Int)
  |           ^^^^^^^
  |   A case class must have at least one leading non-implicit parameter list
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | Example must have at least one leading non-implicit parameter list,
  |  if you're aiming to have a case class parametrized only by implicit ones, you should
  |  add an explicit () as the first parameter list to Example.
   -----------------------------------------------------------------------------

Solution

scala
// Add an explicit empty parameter list before the using clause
case class Example()(using x: Int)
scala
// Or add a regular parameter
case class Example(value: String)(using x: Int)
scala
// If no parameters are needed, consider using a regular class or object
class Example(using x: Int)
<!-- SOURCE-ONLY: Remove the notice below once this page has been manually updated. --> <aside class="warning"> This reference page was created with LLM assistance - the description of the error code may not be accurate or cover all possible scenarios. </aside>