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
object Test:
case Foo // error: only case class or case object allowed
Error
-- [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
classto define a case class - Before
objectto define a case object - Inside
matchexpressions for pattern matching - Inside
enumdefinitions 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:
// Case class
case class Foo(x: Int)
// Case object
case object Bar
// Enum cases
enum Color:
case Red, Green, Blue
In this article