E110: Cyclic Inheritance
E110: Cyclic Inheritance (순환 상속)
클래스나 트레이트가 직접 또는 간접적으로 자기 자신을 상속할 때 나오는 에러예요.
본문
순환 상속은 Scala에서 금지되어 있어요. 자기가 자기 자신을 상속하려면, 상속하기 전에 이미 완전히 정의돼 있어야 하는 모순된 상황이 생기기 때문이에요.
예시
class A extends A
에러 메시지
-- [E110] Syntax Error: example.scala:1:16 -------------------------------------
1 |class A extends A
| ^
| Cyclic inheritance: class A extends itself
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| Cyclic inheritance is prohibited in Dotty.
| Consider the following example:
|
| class A extends A
|
| The example mentioned above would fail because this type of inheritance hierarchy
| creates a "cycle" where a not yet defined class A extends itself which makes
| impossible to instantiate an object of this class
-----------------------------------------------------------------------------
해결 방법
순환 상속을 제거하거나, 올바른 계층 구조로 바꾸면 돼요.
// Remove the cyclic inheritance
class A
// Or create a proper inheritance hierarchy
class Base
class A extends Base