Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`illegal cyclic reference` error in Eclipse / Scala plugin

Tags:

scala

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.

like image 954
Giorgio Avatar asked Nov 03 '22 11:11

Giorgio


1 Answers

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.

like image 170
Mark Butler Avatar answered Nov 15 '22 07:11

Mark Butler