Dreaded Enumerations Issues - What are we doing wrong?

Hi,

We keep getting enumeration related lines marked as invalid in IntelliJ, even though code compliles OK with scalac. And, was wondering whether this is an issue with IntelliJ, or whether we are doing something wrong.

So following the example in scala docs, let's say I have X.scala as follows:

package a

 
object WeekDay extends Enumeration {
  type WeekDay = Value
  val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}



and in another scala file, we have the following:

import a.Weekday._
case class MyData(x: WeekDay)
val oneData = MyData(WeekDay.Mon)



I am getting really weird / inconsistent code errors, e.g.

"Type mismatch, expected: WeekDay.Weekday, actual Weekday.Value" and the line I instantiate oneData gets marked as Red (particularly Weekday.Mon part)

Sometimes, it gets even weirder and I get "red" marker for "type WeekDay = Value" line (on  Value, saying "Cannot resolve symbol Value")

I tried importing a.Weekday or a.Weekday.Weekday, etc.

Sometimes, when you do auto import with IntelliJ , it imports both:

import a.Weekday
import a.Weekday.Weekday

And, the first line (import a.Weekday) is marked gray (as unused import), but when you remove it things start going red again, and you add it back and it gets OK. And, it works fine for a while, then things start getting Red again after a while all of a sudden.

Basically, this is driving us crazy, mainly because it is inconsistent. What is the proper way of using enumerations w/ IntelliJ here, should we get rid of "type Weekday = Value" and not use that aliasing at all?

Just to re-iterate one more time: our code has always compiled fine with scalac even though IntelliJ is marking these lines as Red.

Any recommendations would be greatly appreciated!

Thanks.

1 comment
Comment actions Permalink

Based on your examples I can't reproduce it.
Please create issue with full example and steps to reproduce: https://youtrack.jetbrains.com/issues/SCL#newissue

Another possibility is that it's known issue, which I'm going to fix soon. If it's true, then you have workaround, try File -> Invalidate Caches.

Best regards,
Alexander Podkhalyuzin.

0

Please sign in to leave a comment.