-
Notifications
You must be signed in to change notification settings - Fork 145
8254571: Erroneous generic type inference in a lambda expression with a checked exception #91
8254571: Erroneous generic type inference in a lambda expression with a checked exception #91
Conversation
… a checked exception
👋 Welcome back vromero! A progress list of the required criteria for merging this PR into |
@@ -1238,6 +1239,7 @@ public void visitReference(JCMemberReference tree) { | |||
tree.getOverloadKind() != JCMemberReference.OverloadKind.UNOVERLOADED) { | |||
stuckVars.addAll(freeArgVars); | |||
depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType())); | |||
depVars.addAll(inferenceContext.freeVarsIn(descType.getThrownTypes())); |
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.
did the same for method references given the similarities between both but I couldn't find a test case that reproduced the issue with a method reference
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.
How about:
outer(nested(ConsiderExceptionTVarsInStuckExprs::mightThrow2));
...
static <C> void mightThrow2(C c) throws Exception {}
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.
yep that one makes the trick, thanks
@vicente-romero-oracle 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. |
Webrevs
|
ping |
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 reasonable to me. Not sure if I can foresee the consequences, though.
@@ -1238,6 +1239,7 @@ public void visitReference(JCMemberReference tree) { | |||
tree.getOverloadKind() != JCMemberReference.OverloadKind.UNOVERLOADED) { | |||
stuckVars.addAll(freeArgVars); | |||
depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType())); | |||
depVars.addAll(inferenceContext.freeVarsIn(descType.getThrownTypes())); |
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.
How about:
outer(nested(ConsiderExceptionTVarsInStuckExprs::mightThrow2));
...
static <C> void mightThrow2(C c) throws Exception {}
@vicente-romero-oracle 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 52 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 |
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.
I believe the fix is good. We probably overlooked free type variables in the thrown clause (as they are relatively rare) when doing stuck expression computation. These variables are part of the bound set used by JLS chapter 18, so dropping them on the floor (as current code does) is not a good option. This patch rectifies that.
To test with method references, you would need the method reference to be "non-exact": only in that case will the method reference be considered stuck in the same way the implicit lambda is, I believe.
thanks guys for the review |
/integrate |
Going to push as commit 7e96318.
Your commit was automatically rebased without conflicts. |
@vicente-romero-oracle Pushed as commit 7e96318. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Hi,
The compiler is issuing an error for code like:
there are several things at play here:
So there are three hypothesis here:
The root cause of this bug is that some types escape from Attr with non instantiated type variables in them. I modified the test case to double check if the issue was not related to lambdas, but then the test passed so in the example above I added:
which simulates the lambda and the compiler has no issues compiling this invocation:
so summing up, after double checking the logic of the code that minimized the inference context I realized that the issue is not there. The code is sound and its output only depend on its input, so the issue should be on determining the input. So IMO the issue is in what inference variables we extract from stuck expressions, which is one of the inputs to Infer::roots. Looking for what variables we extract from stuck expressions, I realized that the code currently ignores type variables in the throws clause and this is why my proposed fix is addressing this issue.
Comments?
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk17 pull/91/head:pull/91
$ git checkout pull/91
Update a local copy of the PR:
$ git checkout pull/91
$ git pull https://git.openjdk.java.net/jdk17 pull/91/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 91
View PR using the GUI difftool:
$ git pr show -t 91
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk17/pull/91.diff