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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With