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
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
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
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
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
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 -
Reply all
Reply to author
Forward
0 new messages