It looks like the Scala compiler can't handle enums that implement an interface with a static method that captures the enum type as a method parameter.
Consider the following interface:
//Identifiable.java
package com.example;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
public interface Identifiable {
String name();
static <E extends Enum<E> & Identifiable> Map<String, E> valuesByName(final E[] values) {
return Stream.of(values).collect(toMap(Identifiable::name, Function.identity()));
}
}
And an enum that implements it:
//Size.java
package com.example;
public enum Size implements Identifiable {
SMALL, MEDIUM, LARGE;
}
Finally, a Scala app that uses the Size enum:
//Broken.scala
package com.example
object Broken extends App {
println(Size.SMALL)
}
The following compilation error occurs when attempting to build the classes (in 2.12.3):
Error:(4, 10) illegal cyclic inheritance involving class Size
println(Size.SMALL)
Am I missing something or is this a bug in the compiler?
sbt
, and typed++2.12.3
and thenrun
, and it compiled fine and ran and printedSMALL
. – AndreavaluesByName
from theIdentifiable
but I have no idea why. – Ladida/blah/blah/blah/com/example/Broken.scala:4:10: illegal cyclic inheritance involving class Size
– TabuBroken.scala
to force SBT to recompile it, the build fails again. basically if SBT attempts to compile the Scala file by itself -Compiling 1 Scala source to
- (because the Java files are already compiled), it fails. but if it builds all three from scratch -Compiling 1 Scala source and 2 Java sources to
- it succeeds... – TabuJavaThenScala
produces consistent compilation failures:compileOrder := CompileOrder.JavaThenScala
– Tabu