Skip to content

Enum (extends java) => null in java, when scala looks at it before java  #12637

Open
@benjhm

Description

@benjhm

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions