scala3
scala3 copied to clipboard
Polymorphic extension method corrupts java class containing it: "bad class file"
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 thoughdefaultstill has typeV
It does not compile (but should) if:
- You remove the term clause containing
default - You make
getOrElsean interleaved method
still reproduces in 3.4.2-RC1-bin-20240219
@Kordyjan do you want to remain assigned to this ticket?