Open
Description
Compiler version
Scala 3.0.0, OpenJDK 15.0.2, sbt 1.5.2,
Minimized code
TestenumS.scala
object TestenumS :
def go() = println("Scala: Testme Hello= " + Testme.Hello)
enum Testme extends java.lang.Enum[Testme] :
case Hello
TestenumJ.java
public class TestenumJ {
public static void main(String[] args) {
TestenumS.go(); // line 3 calls Scala to look at Testme
System.out.println("Java: Testme Hello= " + Testme.Hello); //=> null, unless line 3 commented, then => Hello
}
}
Output
[info] running TestenumJ
Scala: Testme Hello= Hello
Java: Testme Hello= null
Expectation
Java: Testme Hello= Hello (not null !!)
It works as expected (Hello) only when line 3 is commented, i.e. when java sees the enum before scala.
As it compiles ok, so the null propagates to cause runtime errors elsewhere, it can takes a long time to find the cause
(especially when it looks ok called from scala)