I have created a folder x
with a source file package.scala
in it.
The file contains the following code:
package x
package object y
{
trait A
case class B extends A
}
Eclipse displays a compilation error: illegal cyclic reference involving object y
.
I am not quite sure what this means. If I try to define a normal class (removing case
) the error message disappears. Another solution is to use a normal object instead of a package object:
package x
object y
{
trait A
case class B extends A
}
Where is the cyclic reference? And how can I remove it? As far as I understand I cannot define a trait and a case subclass of it inside a package object. But I have not clue as to where this restriction comes from.
As PedroFuria says this is a bug, but it's always good to look at the issue associated with the bug in these situations. Specifically the conclusion was back in September 2011:
Defining classes in package objects is only half-working in the Scala compiler itself. You can work around this by defining your class in the right directory. I doubt this will be fully supported any time soon.
So best to refer to this related issue which points out is easy to replace:
package object mypkg {
class MyClass
}
with the following:
package mypkg {
class MyClass
}
Which will work with Eclipse / EclipseIDE.
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