How to auto enumerate cases when writing pattern match?

For example, I have follow list of case class definitions.

trait A
case class B extends A
case class C extends A
case class D extends A

When I write pattern match on A,

def foo(x: A) = x match {
  case B => ???
  case C => ???
  case D => ???

Is there any way to auto fill those case statements "case B, C, D"??? I remember it is possible when develop in Java to handle enumerations.
Btw, I am running Intellij 12 on Mac.

Comment actions Permalink

It's good idea. Thank you! I created the issue:

Best regards,
Alexander Podkhalyuzin.

Comment actions Permalink

The issue state is still 'open'...

Comment actions Permalink

And it's probably going to stay that way... Jetbrains is more interested in Kotlin than Scala these days :-(

Comment actions Permalink

Hi @Fernado Jimenez,

They actually implemented this a few years ago. You can find out how to use it here:

Basically if you pick "case (exhaustive)", it will enumerate all cases automatically for you.


Please sign in to leave a comment.