Skip to content

Fix #7494: check type bounds during java joint compilation #9370

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

Merged
merged 2 commits into from
Jul 21, 2020

Conversation

TheElectronWill
Copy link
Contributor

As @smarter pointed out on gitter, checking every Select of a java-defined symbol would probably be very costly (and still not provide a bullet-proof solution). With this PR, java compilation units are discarded just before Pickler and thus go through additional checks.

@TheElectronWill TheElectronWill linked an issue Jul 15, 2020 that may be closed by this pull request
@TheElectronWill TheElectronWill force-pushed the dont-trust-java branch 2 times, most recently from 7a213be to b9f9260 Compare July 15, 2020 22:13
@smarter
Copy link
Member

smarter commented Jul 16, 2020

There's one failure in the community build:

2020-07-15T22:58:10.6062064Z utest.jvm[0.26.0-bin-SNAPSHOT].compile java.lang.AssertionError: assertion failed: The startSource can be called only once per source file: /__w/dotty/dotty/community-build/community-projects/utest/utest/jvm/src-0/utest/EnableReflectiveInstantiation.java

Which is probably related to the sbt.ExtractDependencies now being run on java sources. I didn't realize we had all this stuff before PostTyper which should not be run on Java units indeed. I think the simplest way to achieve that might be to go back to dropping these units after Frontend, and just have Frontend take care of running the checks on the Java units before it drops them.

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Several approaches were tried in this PR, but I don't think it's useful to keep that in the history, so I suggest squashing this down to two commits: one for the indentation-related changes and one for everything else (and feel free to describe in the commit message why the current approach was chosen in the end)

@TheElectronWill
Copy link
Contributor Author

I agree, it's clearer that way. I've put some explanations in the commit message.

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! One last request: the commit that fixes the issue should contain "Fix #7494" somewhere in its commit message.

Checking every Select of a java-defined symbol would be too costly and still not perfect.
The implemented compromise is to check bounds during the compilation of .java source files.
To do this, a new JavaChecks file is added and called by FrontEnd.
We can't simply discard java compilation units after PostTyper (instead of after Typer),
because sbt.ExtractDependencies (and maybe others) runs before PostTyper and cannot process java sources.
@smarter smarter merged commit 060a17a into scala:master Jul 21, 2020
@TheElectronWill TheElectronWill deleted the dont-trust-java branch August 10, 2020 14:06
odersky added a commit to dotty-staging/dotty that referenced this pull request 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 pull request 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
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

Successfully merging this pull request may close these issues.

The inferred AppliedTypes from Java are not checked
2 participants