Skip to content

Scala 3.3 handling of recursive types in Java differ from javac and Scala 2.13 #17763

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

Closed
andrzejressel opened this issue Jun 4, 2023 · 0 comments · Fixed by #18054
Closed

Comments

@andrzejressel
Copy link
Contributor

Repro repo: https://github.com/andrzejressel/dotty-resursive-java-types

Compiler version

3.3.0

Minimized code

// CopyableBuilder.java
public interface CopyableBuilder<B extends CopyableBuilder<B, T>, T extends ToCopyableBuilder<B, T>> {
}
// ToCopyableBuilder.java
public interface ToCopyableBuilder<B extends CopyableBuilder<B, T>, T extends ToCopyableBuilder<B, T>> {
}
// Crash.scala
// For some reason empty scala class is required? Is sbt invoking javac when there are only java files?
class Crash

Output

[IJ]compile
[info] compiling 1 Scala source and 2 Java sources to D:\MojeProgramy\scala33-crash\target\scala-3.3.0\classes ...
[error] -- [E057] Type Mismatch Error: D:\MojeProgramy\scala33-crash\src\main\java\test\ToCopyableBuilder.java:1:45
[error] 1 |public interface ToCopyableBuilder<B extends CopyableBuilder<B, T>, T extends ToCopyableBuilder<B, T>> {
[error]   |                                             ^
[error]   |Type argument T does not conform to upper bound ToCopyableBuilder[B, T] in subpart CopyableBuilder[B, T] of inferred type  <: CopyableBuilder[B, T]
[error]   |
[error]   | longer explanation available when compiling with `-explain`
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 0 s, completed 4 cze 2023, 16:42:52

Expectation

[IJ]compile
[info] compiling 1 Scala source and 2 Java sources to D:\MojeProgramy\scala33-crash\target\scala-2.13\classes ...
[info] done compiling
[success] Total time: 0 s, completed 4 cze 2023, 16:43:17

Interesting thing is that when these files are ported to Scala they are working fine.

@andrzejressel andrzejressel added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 4, 2023
@jchyb jchyb removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Jun 5, 2023
@odersky odersky self-assigned this Jun 12, 2023
odersky added a commit to dotty-staging/dotty that referenced this issue Jun 25, 2023
Something goes wrong when we try to do mutually recursive F-bounds checking in Java units.
I am not sure what exactly. But in any case, Scala should not try to do Java's typechecking.
So we now check applications in Java units only if they refer to Scala classes.

I added a test for scala#7494, which was originally addressed by scala#9370, the PR which introduced the Java bounds
checking. Adding the test ensures that the new restrictions still glag the original error.

Fixes scala#17763
smarter added a commit that referenced this issue Jun 26, 2023
Something goes wrong when we try to do mutually recursive F-bounds
checking in Java units. I am not sure what exactly. But in any case,
Scala should not try to do Java's typechecking. So we now check
applications in Java units only if they refer to Scala classes.

I added a test for #7494, which was originally addressed by #9370, the
PR which introduced the Java bounds checking. Adding the test ensures
that the new restrictions still flag the original error.

Fixes #17763
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants