-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8261205: AssertionError: Cannot add metadata to an intersection type #4095
8261205: AssertionError: Cannot add metadata to an intersection type #4095
Conversation
👋 Welcome back vromero! A progress list of the required criteria for merging this PR into |
@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
|
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.
What happens if we just use declaredUsingVar
everywhere? Shouldn't that be the "right" way to do it?
yep I also considered that but then realized that parameters of implicit lambdas also have its vartype set to null until the compiler infers a type for them, so the implicitly-typed set and the declared using So thinking again about the naming I think that I can let the method |
I have uploaded a new commit, after an offline comment from Maurizio, he is correct that: given that lambda parameters also have a null type, they will be classified as "declared with var". This commit gets back to the original method name |
@@ -44,7 +44,6 @@ | |||
import static com.sun.tools.javac.code.Kinds.*; | |||
import static com.sun.tools.javac.code.Kinds.Kind.*; | |||
import static com.sun.tools.javac.code.TypeTag.TYPEVAR; | |||
import static com.sun.tools.javac.tree.JCTree.Tag.VARDEF; |
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 import removal changes have been introduced by intelliJ
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 better - one question: what about var
with annotations and lambda parameters? E.g. you can probably construct a similar example involving a lambda parameter - is this fix enough, or would the code path be slightly different?
good catch! I have modified the patch to include the case for lambda parameters declared with |
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 - but I think there's an issue in the test?
|
||
class Test { | ||
void kaa() { | ||
//@A var c = g(1, 1L); |
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.
Is this meant to be commented out?
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.
Ah ok, I see this is fixed now
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, thanks for the review
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.
Thumbs up!
@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 no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
/integrate |
@vicente-romero-oracle Since your change was applied there have been 10 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 81f39ed. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Please review this PR which is adding a field to
JCVariableDecl
, the need I see for this is that when we declare a local variable usingvar
as in:the only clue the compiler has to know that the local variable was declared using
var
is that fieldJCVariableDecl::vartype
is null, but this field is set to an inferred type at some point during the compilation and from that point on there is no way to know for sure that the original AST had avar
or not. Unfortunately there is code that keeps asking if the local variable was implicitly typed or not, after fieldJCVariableDecl::vartype
has been written, and thus making uninformed decisions as in: TypeAnnotations.TypeAnnotationPositions::visitVarDef, where the compiler is implementing a portion of section:9.7.4 Where Annotations May Appear
of the spec (JLS16). In particular the portion that defines how to deal with annotations applied to local variables declared withvar
.The test case above is interesting because the same annotation works as a declaration annotation and as a type annotation. If it were only a type annotation then the compiler would have issued an error before getting to
TypeAnnotations.TypeAnnotationPositions::visitVarDef
, precisely atCheck::validateAnnotation
, see thatCheck::getApplicableTargets
has a special case for local variables declared usingvar
. But again given that the annotation in the example above is applicable as a type and as a declaration annotation, it will seep down to the metadata info associated to the local variable symbol, and that is fine. What is not kosher is that as the compiler has no clue that the AST was originally declared usingvar
that it then tries to type-annotate the type of the local variable. This change is thus making sure that that information is preserved.This patch is also renaming a method in
JCVariableDecl
, its previous name wasisImplicitlyTyped
which was basically checking if thevartype
field wasnull
and was renamed tonullVarType
,hasNullVarType
could be an option too, and a new method was added:declaredUsingVar
which won't change its returned value during the lifetime of a JCVariableDecl AST.TIA
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4095/head:pull/4095
$ git checkout pull/4095
Update a local copy of the PR:
$ git checkout pull/4095
$ git pull https://git.openjdk.java.net/jdk pull/4095/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 4095
View PR using the GUI difftool:
$ git pr show -t 4095
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4095.diff