Skip to content

Polymorphic extension method corrupts java class containing it: "bad class file" #16727

Open
@Sporarum

Description

@Sporarum

Compiler version

scalaVersion: 3.2.2-RC2

Minimized code

Scala file:

class A:
  extension (k: Int)
    def getOrElse[V](default: V): V = ???

Java file:

public class B_2 {

  public static void test() {
    A a = new A();
  }
}

Output

[error]   - java compilation failed with:
[error]       tests/run/java-extension/B_2.java:4: error: cannot access A
[error]           A a = new A();
[error]           ^
[error]         bad class file: out/runAll/run/java-extension/A.class
[error]           undeclared type variable: V
[error]           Please remove or make sure it appears in the correct subdirectory of the classpath.

Expectation

Should compile.
Especially given we do not even access the problematic member, the whole class file is unusable.

Related problems

It compiles (and should) if:

  • You change the result type to for example Int, even though default still has type V

It does not compile (but should) if:

  • You remove the term clause containing default
  • You make getOrElse an interleaved method

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions