Back to Scala3

E088: Expected Start Of Top Level Definition

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

3.8.41.3 KB
Original Source

E088: Expected Start Of Top Level Definition

This error is emitted when modifiers are provided but no valid definition follows them.

After using modifiers like private, protected, final, abstract, etc., you must provide a definition such as class, trait, object, enum, def, val, or var.


Example

scala
final

Error

scala
-- [E088] Syntax Error: example.scala:1:5 --------------------------------------
1 |final
  |     ^
  |     Expected start of definition
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | You have to provide either class, trait, object, or enum definitions after modifiers
   -----------------------------------------------------------------------------

Solution

scala
// Add a definition after the modifier
final class Example
scala
// Or for methods/values
final val x = 42
<!-- 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>