This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Strange "illegal cyclic reference involving value <import>" when compiling an Enumeration

4 replies
Drew
Joined: 2011-12-16,
User offline. Last seen 42 years 45 weeks ago.

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

Drew
Joined: 2011-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Strange "illegal cyclic reference involving value <import>"

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

DaveScala
Joined: 2011-03-18,
User offline. Last seen 1 year 21 weeks ago.
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 -

Drew
Joined: 2011-12-16,
User offline. Last seen 42 years 45 weeks ago.
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 -

DaveScala
Joined: 2011-03-18,
User offline. Last seen 1 year 21 weeks ago.
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 -

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland