E006: 참조한 식별자를 찾을 수 없음

E006: 참조한 식별자를 찾을 수 없음 (Missing Ident)

이 에러는 참조한 식별자(값, 메서드, 타입 등)를 현재 스코프에서 찾을 수 없을 때 발생해요.

출처: Scala 3 Reference

본문

Scala의 모든 식별자에는 그에 대응하는 선언(declaration)이 필요해요. 식별자에는 두 종류가 있어요: 타입 식별자와 값 식별자. 값 식별자는 val, def, object 선언으로 도입되고, 타입 식별자는 type, class, enum, trait 선언으로 도입돼요.

식별자는 자신이 속한 환경에서 대응하는 선언을 참조하거나, 다른 곳에서 임포트(import)될 수 있어요.

대응하는 선언을 찾지 못한 데에는 몇 가지 가능한 이유가 있어요:

  • 선언이나 사용부의 철자가 틀렸다.
  • 임포트가 빠져 있다.
  • 선언은 존재하는데, 용어(term)가 필요한 곳에 타입을 참조했거나 그 반대다.

Example

val result = unknownIdentifier

Error

-- [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

// Declare the identifier before using it
val unknownIdentifier = 42
val result = unknownIdentifier
// Or import it from another scope
import scala.math.Pi
val result = Pi
// Fix the spelling if it was a typo
val knownIdentifier = 42
val result = knownIdentifier

더 알아보기

  • 식별자와 임포트 규칙에 대한 자세한 내용은 "Imports" 및 "Identifiers" 섹션을 참고하세요.