Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False-negative: class needs to be abstract when inherits java class and interface #13074

Open
XYZboom opened this issue Jan 5, 2025 · 9 comments

Comments

@XYZboom
Copy link

XYZboom commented Jan 5, 2025

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.

@lrytz
Copy link
Member

lrytz commented Jan 6, 2025

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 lrytz closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2025
@XYZboom
Copy link
Author

XYZboom commented Jan 6, 2025

@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.

@lrytz
Copy link
Member

lrytz commented Jan 6, 2025

I (again) overlooked what is Scala code.

@lrytz lrytz reopened this Jan 6, 2025
@XYZboom
Copy link
Author

XYZboom commented Jan 6, 2025

I (again) overlooked what is Scala code.

Perhaps the title I gave to the issue was a bit misleading

@som-snytt
Copy link

I tried this out with Lukas's scala/scala#10580 but no difference. I wasn't in a position to disappear down a rabbit hole or warren.

@SethTisue SethTisue changed the title False-negative class needs to be abstract when inherts java class and interface False-negative class needs to be abstract when inherits java class and interface Jan 6, 2025
@SethTisue SethTisue changed the title False-negative class needs to be abstract when inherits java class and interface False-negative: class needs to be abstract when inherits java class and interface Jan 6, 2025
@SethTisue
Copy link
Member

Does Scala 3 handle it correctly?

@som-snytt
Copy link

-- 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?

@XYZboom
Copy link
Author

XYZboom commented Jan 9, 2025

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".

@XYZboom
Copy link
Author

XYZboom commented Jan 9, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants