While this works as expected:
trait A
trait B extends A
object C extends A with B
The following yields illegal cyclic reference involving trait B :
package cyclictest {
trait A
trait B extends A
}
package object cyclictest extends A with B
What´s happening there?
The error is correct. The compiler resolves names
AandBto the fully qualified names, so what the typechecker sees is:In order to check that the package object definition is correct, the compiler needs to know all the members of
AandB, but in order to know that, it needs to know the members ofcyclictest(sinceAandBare members ofcyclictest). However, this happens while defining cyclictest, therefore you have a cycle that can’t be resolved.The first case passes because the package
cyclictestdoes not inherit anything, it is the default directory-based package.