E139: Unknown Named Enclosing Class Or Object — 알 수 없는 이름의 바깥 클래스 또는 객체
E139: Unknown Named Enclosing Class Or Object — 알 수 없는 이름의 바깥 클래스 또는 객체
가시성 수식어가 바깥 스코프에서 찾을 수 없는 클래스나 객체 이름을 참조할 때 발생하는 에러예요.
본문
가시성 수식어가 바깥 스코프에서 찾을 수 없는 클래스나 객체 이름을 참조할 때 발생해요.
Scala에서는 private[ClassName]나 protected[PackageName]처럼 한정된 privat/protected 수식어를 써서 특정 바깥 클래스·객체·패키지로 가시성을 제한할 수 있어요. 이 에러는 지정한 이름이 어떤 바깥 스코프와도 일치하지 않을 때 발생해요.
가시성 수식어에 적힌 클래스나 객체 이름이 사용됐는데 해석할 수 없었던 거예요. 이름이 철자가 틀리지 않았는지, 실제로 존재하는 바깥 클래스·객체·패키지를 가리키는지 확인해보세요.
예시
class Example:
private[NonExistent] val x: Int = 42
에러
-- [E139] Reference Error: example.scala:2:27 ----------------------------------
2 | private[NonExistent] val x: Int = 42
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| no enclosing class or object is named 'NonExistent'
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| The class or object named 'NonExistent' was used as a visibility
| modifier, but could not be resolved. Make sure that
| 'NonExistent' is not misspelled and has been imported into the
| current scope.
|
-----------------------------------------------------------------------------
해결 방법
올바른 바깥 클래스 이름을 사용하면 돼요.
// Use the correct enclosing class name
class Example:
private[Example] val x: Int = 42
아니면 단순한 private 수식어를 써도 되고요.
// Alternative: Use a simple private modifier
class Example:
private val x: Int = 42