Back to Scala3

E079: Only Case Class Or Case Object Allowed

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

3.8.41.4 KB
Original Source

E079: Only Case Class Or Case Object Allowed

Note: This error was removed before Scala 3.0.0 was released and was never emitted by the Scala 3 compiler.

What it did

This error was triggered in early Dotty versions when using case keyword outside of a valid context.

Example

scala
object Test:
  case Foo  // error: only case class or case object allowed

Error

scala
-- [E079] Syntax Error: example.scala:2:2 --------------------------------------
2 |  case Foo
  |  ^^^^^^^^
  |  Only `case class` or `case object` allowed

Explanation

The case keyword can only be used in specific contexts:

  • Before class to define a case class
  • Before object to define a case object
  • Inside match expressions for pattern matching
  • Inside enum definitions for enum cases

This error was removed in commit 2e5df79218 (May 2021) as part of "Refactor remaining statement and declaration loops". The parser was refactored to handle invalid syntax differently.

The correct usages are:

scala
// Case class
case class Foo(x: Int)

// Case object
case object Bar

// Enum cases
enum Color:
  case Red, Green, Blue
<!-- 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>