E149: 표준 종류(Standard Kind)의 재정의는 불법이에요

E149: 표준 종류(Standard Kind)의 재정의는 불법이에요 (Illegal Redefinition Of Standard Kind)

scala 패키지 안에서 Scala의 핵심 타입을 위해 예약된 이름으로 class나 object를 정의하려 할 때 발생하는 에러예요.

출처: Scala 3 Reference

본문

예약된 이름에는 Any, Nothing, AnyRef, AnyVal, Null, Unit 같은 기초 타입과 그 외 Scala의 핵심 class들이 포함돼요. 이 이름들은 컴파일러가 합성(synthesize)하고 특별한 의미를 갖기 때문에 예약되어 있는데, 사용자가 정의한 class로는 그 의미를 재현할 수 없어요.

Example

package scala

class Any

Error

-- [E149] Syntax Error: example.scala:3:6 --------------------------------------
3 |class Any
  |      ^^^
  |      illegal redefinition of standard class Any
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |  "Any" is a standard Scala core `class`
  |  Please choose a different name to avoid conflicts
   -----------------------------------------------------------------------------

Solution

package scala

// Choose a different name that doesn't conflict with reserved names
class MyAny

참고: 이 에러는 scala 패키지 안에서 class를 정의할 때만 발생할 수 있어요. 다른 패키지의 일반 사용자 코드에서는 Any 같은 이름을 자유롭게 쓸 수 있지만, 명확성을 위해 권장되지는 않아요.