Open
Description
Compiler version
➜ snips ~/projects/dotty/bin/scala -version
Starting scala3 REPL...
Scala compiler version 3.0.0-RC1-bin-SNAPSHOT-git-ce684de -- Copyright 2002-2021, LAMP/EPFL
Minimized code
Starting scala3 REPL...
scala> enum E extends Enum[Nothing] { case X }
// defined class E
scala> E.values
val res0: Array[E] = Array(X)
scala> E.X.getDeclaringClass.getEnumConstants
java.lang.ClassCastException: class [Lrs$line$1$E; cannot be cast to class [Lscala.runtime.Nothing$; ([Lrs$line$1$E; is in unnamed module of loader dotty.tools.repl.AbstractFileClassLoader @d180961; [Lscala.runtime.Nothing$; is in unnamed module of loader java.net.URLClassLoader @4de158ca)
... 27 elided
Output
java.lang.ClassCastException
Expectation
I expect an error at compile time for the bad type arg. Or maybe values
is Array[Nothing]
and throws if non-empty. (I see that Enumerations must contain at least one case
.)
Alternatively, maybe it is allowed in Scala but the implementation is tweaked so that Java reflection sees a different (lower bound of) the enum type.