Back to Scala3

E004: Case Class Missing Param List

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

3.8.41.7 KB
Original Source

E004: Case Class Missing Param List

This error is emitted when a case class is defined without any parameter list. In Scala 3, case classes must have at least one parameter list.

Empty must have at least one parameter list. If you would rather have a singleton representation of Empty, use a case object. Or, add an explicit () as a parameter list to Empty.


Example

scala
case class Empty

Error

scala
-- [E004] Syntax Error: example.scala:1:11 -------------------------------------
1 |case class Empty
  |           ^^^^^
  |           A case class must have at least one parameter list
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | Empty must have at least one parameter list, if you would rather
  | have a singleton representation of Empty, use a "case object".
  | Or, add an explicit () as a parameter list to Empty.
   -----------------------------------------------------------------------------

Solution

scala
// Use case object for singleton representation
case object Empty
scala
// Add an explicit empty parameter list
case class Empty()
scala
// Or define actual parameters
case class Empty(value: String)
<!-- 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>