- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Strange "illegal cyclic reference involving value <import>" when compiling an Enumeration
Mon, 2012-01-16, 21:31
Hi Everyone,
I have the following code in User.scala, when I compile it, I get a
strange "illegal cyclic reference involving value ". What's
the problem?
import User.UserStatus._
class User extends AbstractModel {
var id: Int = 0
var email: String = null
var password: String = null
var userStatus: UserStatus = null
}
object User {
object UserStatus extends Enumeration {
type UserStatus = Value
val Active = Value("1")
val Disabled = Value("2")
}
}
Here's the compiler's output:
[error] User.scala:20: illegal cyclic reference involving value
[error] object UserStatus extends Enumeration {
[error] ^
[error] User.scala:21: not found: type Value
[error] type UserStatus = Value
[error] ^
[error] User.scala:23: not found: value Value
[error] val Active = Value(1)
[error] ^
[error] User.scala:24: not found: value Value
[error] val Disabled = Value(2)
[error] ^
Thanks,
Drew
Tue, 2012-01-17, 01:21
#2
Re: Strange "illegal cyclic reference involving value <import>"
The order is wrong:
First define the enumeration
Then import the enumeration type in the context/scope
And then use it
Like so:
object User {
object UserStatus extends Enumeration {
type UserStatus = Value
val Active = Value("1")
val Disabled = Value("2")
}
}
import User.UserStatus._
class User extends AbstractModel {
var id: Int = 0
var email: String = null
var password: String = null
var userStatus: UserStatus = null
}
On 17 jan, 00:31, Drew wrote:
> I still can't seem to be able to figure out what's going on. Is this a
> bug?
>
> On Jan 16, 12:31 pm, Drew wrote:
>
>
>
> > Hi Everyone,
>
> > I have the following code in User.scala, when I compile it, I get a
> > strange "illegal cyclic reference involving value ". What's
> > the problem?
>
> > import User.UserStatus._
>
> > class User extends AbstractModel {
> > var id: Int = 0
> > var email: String = null
> > var password: String = null
> > var userStatus: UserStatus = null
>
> > }
>
> > object User {
> > object UserStatus extends Enumeration {
> > type UserStatus = Value
>
> > val Active = Value("1")
> > val Disabled = Value("2")
> > }
>
> > }
>
> > Here's the compiler's output:
>
> > [error] User.scala:20: illegal cyclic reference involving value
> >
> > [error] object UserStatus extends Enumeration {
> > [error] ^
> > [error] User.scala:21: not found: type Value
> > [error] type UserStatus = Value
> > [error] ^
> > [error] User.scala:23: not found: value Value
> > [error] val Active = Value(1)
> > [error] ^
> > [error] User.scala:24: not found: value Value
> > [error] val Disabled = Value(2)
> > [error] ^
>
> > Thanks,
>
> > Drew- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -
Tue, 2012-01-17, 01:31
#3
Re: Strange "illegal cyclic reference involving value <import>"
Thanks Dave, that fixed it. I didn't know the order mattered when
defining the class and it's companion object.
On Jan 16, 4:12 pm, Dave wrote:
> The order is wrong:
> First define the enumeration
> Then import the enumeration type in the context/scope
> And then use it
>
> Like so:
>
> object User {
> object UserStatus extends Enumeration {
> type UserStatus = Value
>
> val Active = Value("1")
> val Disabled = Value("2")
> }
> }
> import User.UserStatus._
>
> class User extends AbstractModel {
> var id: Int = 0
> var email: String = null
> var password: String = null
> var userStatus: UserStatus = null
> }
>
> On 17 jan, 00:31, Drew wrote:
>
>
>
>
>
>
>
> > I still can't seem to be able to figure out what's going on. Is this a
> > bug?
>
> > On Jan 16, 12:31 pm, Drew wrote:
>
> > > Hi Everyone,
>
> > > I have the following code in User.scala, when I compile it, I get a
> > > strange "illegal cyclic reference involving value ". What's
> > > the problem?
>
> > > import User.UserStatus._
>
> > > class User extends AbstractModel {
> > > var id: Int = 0
> > > var email: String = null
> > > var password: String = null
> > > var userStatus: UserStatus = null
>
> > > }
>
> > > object User {
> > > object UserStatus extends Enumeration {
> > > type UserStatus = Value
>
> > > val Active = Value("1")
> > > val Disabled = Value("2")
> > > }
>
> > > }
>
> > > Here's the compiler's output:
>
> > > [error] User.scala:20: illegal cyclic reference involving value
> > >
> > > [error] object UserStatus extends Enumeration {
> > > [error] ^
> > > [error] User.scala:21: not found: type Value
> > > [error] type UserStatus = Value
> > > [error] ^
> > > [error] User.scala:23: not found: value Value
> > > [error] val Active = Value(1)
> > > [error] ^
> > > [error] User.scala:24: not found: value Value
> > > [error] val Disabled = Value(2)
> > > [error] ^
>
> > > Thanks,
>
> > > Drew- Tekst uit oorspronkelijk bericht niet weergeven -
>
> > - Tekst uit oorspronkelijk bericht weergeven -
Tue, 2012-01-17, 01:41
#4
Re: Strange "illegal cyclic reference involving value <import>"
Normally not, but it is the type UserStatus:
type UserStatus = Value
that must come in scope.
On 17 jan, 01:19, Drew wrote:
> Thanks Dave, that fixed it. I didn't know the order mattered when
> defining the class and it's companion object.
>
> On Jan 16, 4:12 pm, Dave wrote:
>
>
>
> > The order is wrong:
> > First define the enumeration
> > Then import the enumeration type in the context/scope
> > And then use it
>
> > Like so:
>
> > object User {
> > object UserStatus extends Enumeration {
> > type UserStatus = Value
>
> > val Active = Value("1")
> > val Disabled = Value("2")
> > }
> > }
> > import User.UserStatus._
>
> > class User extends AbstractModel {
> > var id: Int = 0
> > var email: String = null
> > var password: String = null
> > var userStatus: UserStatus = null
> > }
>
> > On 17 jan, 00:31, Drew wrote:
>
> > > I still can't seem to be able to figure out what's going on. Is this a
> > > bug?
>
> > > On Jan 16, 12:31 pm, Drew wrote:
>
> > > > Hi Everyone,
>
> > > > I have the following code in User.scala, when I compile it, I get a
> > > > strange "illegal cyclic reference involving value ". What's
> > > > the problem?
>
> > > > import User.UserStatus._
>
> > > > class User extends AbstractModel {
> > > > var id: Int = 0
> > > > var email: String = null
> > > > var password: String = null
> > > > var userStatus: UserStatus = null
>
> > > > }
>
> > > > object User {
> > > > object UserStatus extends Enumeration {
> > > > type UserStatus = Value
>
> > > > val Active = Value("1")
> > > > val Disabled = Value("2")
> > > > }
>
> > > > }
>
> > > > Here's the compiler's output:
>
> > > > [error] User.scala:20: illegal cyclic reference involving value
> > > >
> > > > [error] object UserStatus extends Enumeration {
> > > > [error] ^
> > > > [error] User.scala:21: not found: type Value
> > > > [error] type UserStatus = Value
> > > > [error] ^
> > > > [error] User.scala:23: not found: value Value
> > > > [error] val Active = Value(1)
> > > > [error] ^
> > > > [error] User.scala:24: not found: value Value
> > > > [error] val Disabled = Value(2)
> > > > [error] ^
>
> > > > Thanks,
>
> > > > Drew- Tekst uit oorspronkelijk bericht niet weergeven -
>
> > > - Tekst uit oorspronkelijk bericht weergeven -- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -
I still can't seem to be able to figure out what's going on. Is this a
bug?
On Jan 16, 12:31 pm, Drew wrote:
> Hi Everyone,
>
> I have the following code in User.scala, when I compile it, I get a
> strange "illegal cyclic reference involving value ". What's
> the problem?
>
> import User.UserStatus._
>
> class User extends AbstractModel {
> var id: Int = 0
> var email: String = null
> var password: String = null
> var userStatus: UserStatus = null
>
> }
>
> object User {
> object UserStatus extends Enumeration {
> type UserStatus = Value
>
> val Active = Value("1")
> val Disabled = Value("2")
> }
>
> }
>
> Here's the compiler's output:
>
> [error] User.scala:20: illegal cyclic reference involving value
>
> [error] object UserStatus extends Enumeration {
> [error] ^
> [error] User.scala:21: not found: type Value
> [error] type UserStatus = Value
> [error] ^
> [error] User.scala:23: not found: value Value
> [error] val Active = Value(1)
> [error] ^
> [error] User.scala:24: not found: value Value
> [error] val Disabled = Value(2)
> [error] ^
>
> Thanks,
>
> Drew