Back to Scala3

E025: Identifier Expected

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

3.8.41.4 KB
Original Source

E025: Identifier Expected

This error is emitted when the parser expects an identifier but finds something else, typically when an invalid token is used where a name is required.

This can occur when for example when a type annotation uses something that is not a valid identifier.


Example

scala
object obj2:
  val a: this = ???

Error

scala
-- [E025] Syntax Error: example.scala:2:9 --------------------------------------
2 |  val a: this = ???
  |         ^^^^
  |         identifier expected
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | An identifier expected, but this found. This could be because
  | this is not a valid identifier. As a workaround, the compiler could
  | infer the type for you. For example, instead of:
  |
  | def foo: this = {...}
  |
  | Write your code like:
  |
  | def foo = {...}
   -----------------------------------------------------------------------------

Solution

scala
object obj2:
  val a: this.type = ???
<!-- 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>