private/protected 한정자가 중복되었어요

private/protected 한정자가 중복되었어요 (E087: Duplicate Private Protected Qualifier)

같은 정의에 스코프 한정자(예: [ClassName])가 붙은 privateprotected를 함께 쓰면 이 에러가 나요. 서로 다른 스코프로 한정해도 둘을 조합할 수 없어요.

출처: Scala 3 Reference

본문

같은 정의에 스코프 한정자(scope qualifier, 예: [ClassName])가 붙은 privateprotected 수식어를 모두 사용하면 이 에러가 발생해요.

privateprotected 수식어는 서로 다른 스코프로 한정된다 해도 함께 조합할 수 없어요. 한 멤버는 하나의 접근 수식어만 가질 수 있어요.

예시 (Example)

class Example:
  private[Example] protected[Example] def method: Int = 42

에러 (Error)

-- [E087] Syntax Error: example.scala:2:28 -------------------------------------
2 |  private[Example] protected[Example] def method: Int = 42
  |                            ^
  |                            Duplicate private/protected modifier
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | It is not allowed to combine `private` and `protected` modifiers even if they are qualified to different scopes
   -----------------------------------------------------------------------------

해결 방법 (Solution)

접근 수식어는 하나만 사용해요.

// Use only one access modifier
class Example:
  protected[Example] def method: Int = 42