Blending the dash into a package object twice

So far, this works as expected:

trait A trait B extends A object C extends A with B 

illegal cyclic reference involving trait B :

 package cyclictest { trait A trait B extends A } package object cyclictest extends A with B 

What is happening there?

+6
source share
1 answer

The error is correct. The compiler resolves the names A and B for full names, so what typechecker sees is:

 package object cyclictest extends cyclictest.A with cyclictest.B 

To verify that the package object definition is correct, the compiler must know all members A and B , but in order to know this, it needs to know the members of cyclictest (since A and B are members of cyclictest ). However, this happens when determining the cyclicality, so you have a loop that cannot be resolved.

The first case passes because the cyclictest package cyclictest not inherit anything; it is a directory-based package by default.

+2
source

Source: https://habr.com/ru/post/899060/


All Articles