开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜