-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
8338288: Compiler Implementation for Flexible Constructor Bodies (Third Preview) #21410
base: master
Are you sure you want to change the base?
8338288: Compiler Implementation for Flexible Constructor Bodies (Third Preview) #21410
Conversation
Improve diagnostic for invalid local class creation
👋 Welcome back mcimadamore! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
@mcimadamore The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
/csr |
@mcimadamore has indicated that a compatibility and specification (CSR) request is needed for this pull request. @mcimadamore please create a CSR request for issue JDK-8338288 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
/solves 8322882 |
@mcimadamore |
@mcimadamore |
/issue remove JDK-8341469 |
@mcimadamore The issue |
FYI, I verified that this patch also fixes JDK-8330037, which is a variant of the "you can't capture a free variable across a static method boundary" problem. |
/solves 8330037 |
@mcimadamore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This PR contains the implementation for the third iteration of the Flexible Constructor Bodies feature.
While the feature remains largely unchanged from the previous iteration, this PR fixes some of the checks that are applied when a new inner class (whether member, local or anonymous) is constructed, either via new, or, indirectly, via super. These checks currently reside in
Resolve::resolveImplicitThis
, but this routine fails to take into account the differences between the various cases (e.g. the checks for member inner classes are different than those for local/anon classes), and this results in spurious compilation errors. Below is an attempt to describe what should happen, in the various cases.Member inner classes
Whenever we see
new M()
whereM
is a member inner class, we need to lookup someE.this
(whereE
is a class enclosingM
), given none is provided. This same issue is also present when checking asuper(...)
constructor call: if the superclass is a member inner classM
, then validating the constructor call implies inferring a suitable enclosing instance forM
, as if we were checkingnew M()
.The lookup process for should look at all the enclosing instances available to us, and pick the innermost enclosing instance of type
E
such thatE
is a subclass ofM
's enclosing class. It should be the case thatE.this
is accessible (e.g. not in E‘s early construction context) or a compile-time error should occur.This new check is defined in
Resolve::findSelfContaining
.Local and anonymous inner classes
When creating local and anonymous inner classes defined in a
static
method, we should not check for the availability of an enclosing instance, as JLS 15.9.2 is silent about this (such classes have no enclosing instance). What matters, for local and anon classes defined instatic
methods, is that the class creation expression occurs in a context where we can access local variables defined in the method in which the local class is defined. This means that code like the one in theLocalFreeVarStaticInstantiate
test is now correctly rejected.This new check is defined in
Resolve::findLocalClassOwner
. While writing the code and looking at tests, I realized that existing diagnostics were not sufficient to capture this new condition. So I added a new one.Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21410/head:pull/21410
$ git checkout pull/21410
Update a local copy of the PR:
$ git checkout pull/21410
$ git pull https://git.openjdk.org/jdk.git pull/21410/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 21410
View PR using the GUI difftool:
$ git pr show -t 21410
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21410.diff
Webrev
Link to Webrev Comment