Allow local class creation in early construction context#1089
Allow local class creation in early construction context#1089mcimadamore wants to merge 1 commit into
Conversation
|
/template append |
|
👋 Welcome back mcimadamore! A progress list of the required criteria for merging this PR into |
|
@mcimadamore This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 1 new commit pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
|
@mcimadamore The pull request template has been appended to the pull request body |
PaulSandoz
left a comment
There was a problem hiding this comment.
Very good. This expands the use of where records can be used in reflectable lambdas.
|
/integrate |
|
@mcimadamore Pushed as commit 835ba45. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Some time ago, I added a restriction to reject local class creation in early context. The reason this restriction was added is that capture of "this" in local classes in early context work differently, in the sense that a local class in such context is allowed to capture an outer this, but not the current this.
Example:
This is legal, as the local class needs
Outer.this, notInner.this.But, the babylon compiler features several restriction when it comes to inner classes and constructors:
Now, (1) seems promising (after all, you only are in early construction context if you are... in a constructor). But, you can still have a reflectable lambda in a constructor:
Except -- this still fails, beause of (2) -- the reflectable lambda is inside an inner class (Inner).
For these reasons, I don't think it's possible to ever trigger a case where strange outer this capturing would be relevant. For this to happen the local class has to be inside a constructor of an inner class. And, inside that constructor we can't, by definition, have reflectable elements.
The equivalent example w/o inner classes:
Is still rejected by the current AST check, but in fact there's nothing problematic about this. So this PR re-allows this.
I've added a test to make sure this shape works correctly -- unfortunately I couldn't rely on the
@IRtest harness (as that requires the reflectable element to be inside a reflectable method, which is not the case here), so I have hand-rolled a new test.Progress
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/babylon.git pull/1089/head:pull/1089$ git checkout pull/1089Update a local copy of the PR:
$ git checkout pull/1089$ git pull https://git.openjdk.org/babylon.git pull/1089/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 1089View PR using the GUI difftool:
$ git pr show -t 1089Using diff file
Download this PR as a diff file:
https://git.openjdk.org/babylon/pull/1089.diff
Using Webrev
Link to Webrev Comment