-
Notifications
You must be signed in to change notification settings - Fork 5.9k
8333766: Stack overflow with anonymous class in super() parameter #19604
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
Conversation
👋 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 123 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
if (currentClass != null && typesUnderConstruction.contains(currentClass)) { | ||
// reference must be to enclosing outer instance, mutate capture kind. | ||
Assert.check(sym != currentClass); // should have been caught right in Attr | ||
if (currentClass != null && currentClass != sym && !outerThisReachable(currentClass.type, sym)) { |
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.
There is a subtle change here - note that now if currentClass == sym
we just skip this part (in this case just using this
is enough).
@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. |
} else if (current.tsym.isSubClass(target, types)) { | ||
return true; | ||
} else { | ||
return current.tsym.hasOuterInstance() && |
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.
note that hasOuterInstance
takes into account the NOOUTERTHIS
flag, that is, whether the inner class can have an enclosing instance at all.
@@ -2130,6 +2131,17 @@ void addSymbol(Symbol sym, LambdaSymbolKind skind) { | |||
} | |||
} | |||
|
|||
private boolean outerThisReachable(Type current, Symbol target) { |
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.
The idea here is: if we can reach the target symbol from the current one w/o traversing any type under construction, or any type for which NOOUTERTHIS
is set, then we can consider the target T.this
reachable.
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.
Makes sense to me.
Closing this PR. This issue is related to other issues such as https://bugs.openjdk.org/browse/JDK-8334037, which can only be fixed reliably with a more invasive refactoring which moves Lower ahead of LambdaToMethod. |
This patch fixes an issue in
LambdaToMethod
where the wrong code is generated to access a symbol in the enclosing scope.LambdaTranslationContext::addSymbol
has some logic to avoid referring toT.this
whenT
is a type under construction. This fix works well when a lambda is directly enclosed in asuper
orthis
call, but does not scale to more complex cases, such as the one in this issue.A more complete fix needs to check whether the target
T.this
is really available via a chain of enclosingthis$n
fields. If that's not the case, thenT.this
must be captured by the lambda more directly, as there's no path to it from the innermost enclosing this.To detect that, I've added a method (
outerThisReachable
) which more or less mimic the lookup logic inLower::makeOwnerThisN
.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19604/head:pull/19604
$ git checkout pull/19604
Update a local copy of the PR:
$ git checkout pull/19604
$ git pull https://git.openjdk.org/jdk.git pull/19604/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19604
View PR using the GUI difftool:
$ git pr show -t 19604
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19604.diff
Webrev
Link to Webrev Comment