bug
bug copied to clipboard
False-negative: class needs to be abstract when inherits java class and interface
Reproduction steps
Scala version: 2.13.15
// FILE: I0.java
public interface I0<T> {
public void func(A<String> a, T s);
}
// FILE: I1.java
public interface I1 extends I0<String> {
public default void func(A<Object> a, String s) {
}
}
class A[T0]
class A0 extends I1 {
}
Problem
The compiler passed the code above.
There should be a class A0 needs to be abstract here.
The Scala compiler only reads Java source files (in mixed compilation) to know their signatures, but it does not produce .class files for them. Java sources are not checked for correctness, many checks are skipped. We delegate checking to the Java compiler, which needs to processe Java sources anyway after mixed compilation.
@lrytz Yes, I understand the working principle of scalac, which is similar to Kotlin's delegation of Javac to compile Java source code. In this issue, what I want to express is that class A0 should give an error because it does not implement abstract method func in the Java interface, but in fact the compiler passed this code.
I (again) overlooked what is Scala code.
I (again) overlooked what is Scala code.
Perhaps the title I gave to the issue was a bit misleading
I tried this out with Lukas's https://github.com/scala/scala/pull/10580 but no difference. I wasn't in a position to disappear down a rabbit hole or warren.
Does Scala 3 handle it correctly?
-- Error: test/files/neg/t13074/b.scala:2:6 ----------------------------------------------------------------------------
2 |class B extends I1
| ^
| class B needs to be abstract, since def f(x$0: A[String], x$1: T): Unit in trait I0 is not defined
| (The class implements a member with a different type: def f(x$0: A[Object], x$1: String): Unit in trait I1)
1 error found
The bug template needs a new section for What does Dotty do?
Perhaps I have made some new discoveries, and this bug may be a Javac bug. Change I1 to the following code, Javac will report a "name clash".
interface I1 extends I0<Object> {
public default void func(A<Object> a, Object s) {
}
}
If change Object in I0<Object> to another type, such as I0<String>, Javac will not report a "name clash".
Java developers have reproduced this bug in JDK-8347330. But before they fix this bug, Scala2 should also report an error like what Scala3 does.
Java developers currently do not believe that this is a bug in Javac