-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8332600: javac uses record components source position during compilation #20148
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
8332600: javac uses record components source position during compilation #20148
Conversation
👋 Welcome back vromero! A progress list of the required criteria for merging this PR into |
@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 77 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 |
@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
|
@@ -1139,7 +1139,8 @@ public void visitMethodDef(JCMethodDecl tree) { | |||
for (JCVariableDecl param: tree.params) { | |||
boolean paramIsVarArgs = (param.sym.flags_field & VARARGS) != 0; | |||
if (!types.isSameType(param.type, recordFieldTypes.head) || | |||
(recordComponents.head.isVarargs() != paramIsVarArgs)) { | |||
(recordComponents.head != null && |
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 am afraid recordComponents.head != null
(which is basically recordComponents.isEmpty()
, I think) is probably insufficient here. Consider e.g.:
record R(int x, int x, int x) {}
which will fail as recordComponents
itself will be null
, due to tail
being null
.
Looking at the last record component (.last()
) might be one of the solutions?
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 have changed the code a bit, I think it make more sense now, thanks for the comments
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.
Seems OK to me.
thanks for the review |
/integrate |
Going to push as commit 245c086.
Your commit was automatically rebased without conflicts. |
@vicente-romero-oracle Pushed as commit 245c086. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
javac uses the source position of record components to find and later probably remove a given record component during compilation. This could be necessary if annotation processors are present. This is done in part to provide better error messages for silly record definitions like:
record R(int i, float i) {} // two record components with the same name
but this is brittle and can backfire if the record is read from a class file as the source positions are not stored there. See JDK-8332297 for some context
The idea of this fix is not to use the source position but only the name to find a given record component. This could imply that if the user defines an erroneous record like the one above, then the record could end up with less record components than expected but records like this wouldn't compile anyway
TIA
Progress
Warning
8332600: javac uses record components source position during compilation
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20148/head:pull/20148
$ git checkout pull/20148
Update a local copy of the PR:
$ git checkout pull/20148
$ git pull https://git.openjdk.org/jdk.git pull/20148/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 20148
View PR using the GUI difftool:
$ git pr show -t 20148
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20148.diff
Webrev
Link to Webrev Comment