Strange "illegal cyclic reference involving value <import>" when compiling an Enumeration
524 views
Skip to first unread message
Drew
unread,
Jan 16, 2012, 3:31:35 PM1/16/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala-user
Hi Everyone,
I have the following code in User.scala, when I compile it, I get a
strange "illegal cyclic reference involving value <import>". 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
<import>
[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
unread,
Jan 16, 2012, 6:31:09 PM1/16/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala-user
I still can't seem to be able to figure out what's going on. Is this a
bug?
Dave
unread,
Jan 16, 2012, 7:12:28 PM1/16/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala-user
The order is wrong:
First define the enumeration
Then import the enumeration type in the context/scope
And then use it
Like so:
> > Drew- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -
Drew
unread,
Jan 16, 2012, 7:19:26 PM1/16/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala-user
Thanks Dave, that fixed it. I didn't know the order mattered when
defining the class and it's companion object.
Dave
unread,
Jan 16, 2012, 7:31:18 PM1/16/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala-user
Normally not, but it is the type UserStatus:
type UserStatus = Value
that must come in scope.
> > > - Tekst uit oorspronkelijk bericht weergeven -- Tekst uit oorspronkelijk bericht niet weergeven -