Mixin in a trait into a package object twice
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 cyclict开发者_StackOverflowest {
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 A
and B
to the fully qualified names, so what the typechecker sees is:
package object cyclictest extends cyclictest.A with cyclictest.B
In order to check that the package object definition is correct, the compiler needs to know all the members of A
and B
, but in order to know that, it needs to know the members of cyclictest
(since A
and B
are members of cyclictest
). However, this happens while defining cyclictest, therefore you have a cycle that can't be resolved.
The first case passes because the package cyclictest
does not inherit anything, it is the default directory-based package.
精彩评论