Back to Scala3

E006: Missing Ident

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

3.8.42.5 KB
Original Source

E006: Missing Ident

This error is emitted when a referenced identifier (value, method, type, etc.) cannot be found in the current scope.

Each identifier in Scala needs a matching declaration. There are two kinds of identifiers: type identifiers and value identifiers. Value identifiers are introduced by val, def, or object declarations. Type identifiers are introduced by type, class, enum, or trait declarations.

Identifiers refer to matching declarations in their environment, or they can be imported from elsewhere.

Possible reasons why no matching declaration was found:

  • The declaration or the use is mis-spelt.
  • An import is missing.

Example

scala
val result = unknownIdentifier

Error

scala
-- [E006] Not Found Error: example.scala:1:13 ----------------------------------
1 |val result = unknownIdentifier
  |             ^^^^^^^^^^^^^^^^^
  |             Not found: unknownIdentifier
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | Each identifier in Scala needs a matching declaration. There are two kinds of
  | identifiers: type identifiers and value identifiers. Value identifiers are introduced
  | by `val`, `def`, or `object` declarations. Type identifiers are introduced by `type`,
  | `class`, `enum`, or `trait` declarations.
  |
  | Identifiers refer to matching declarations in their environment, or they can be
  | imported from elsewhere.
  |
  | Possible reasons why no matching declaration was found:
  |  - The declaration or the use is misspelled.
  |  - An import is missing.
  |  - The declaration exists but refers to a type in a context where a term is expected, or vice-versa.
   -----------------------------------------------------------------------------

Solution

scala
// Declare the identifier before using it
val unknownIdentifier = 42
val result = unknownIdentifier
scala
// Or import it from another scope
import scala.math.Pi
val result = Pi
scala
// Fix the spelling if it was a typo
val knownIdentifier = 42
val result = knownIdentifier
<!-- 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>