-
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
8263642: javac emits duplicate checkcast for first bound of intersection type in cast #3399
Conversation
👋 Welcome back lgxbslgx! A progress list of the required criteria for merging this PR into |
Webrevs
|
@lgxbslgx This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Ping. Could I ask your help to review this patch? Thanks a lot. |
Code_attribute code_attribute = (Code_attribute) method.attributes.get(Attribute.Code); | ||
for (Instruction instruction : code_attribute.getInstructions()) { | ||
if ("checkcast".equals(instruction.getMnemonic())) { | ||
checkcastNumber++; |
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 think that the test should check not only for the number of checkcast but also for the type the checkcast is checking against.
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.
Added.
@@ -2221,7 +2221,8 @@ public void visitTypeCast(JCTypeCast tree) { | |||
// the conversion. | |||
if (!tree.clazz.type.isPrimitive() && | |||
!types.isSameType(tree.expr.type, tree.clazz.type) && | |||
types.asSuper(tree.expr.type, tree.clazz.type.tsym) == null) { | |||
types.asSuper(tree.expr.type, tree.clazz.type.tsym) == null && | |||
tree.clazz.getTag() != TYPEINTERSECTION) { |
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 think that if the right form of the AST is one that have only two type casts, then that's what the fix should be doing
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 revised the patch to adjust the AST. Now it has only two type casts instead of three.
@vicente-romero-oracle Thanks for your review. I updated the patch just now. |
throw new AssertionError("The number of the instruction 'checkcast' is not right. " + | ||
"Expected number: 2, actual number: " + checkCastList.size()); | ||
} | ||
// first checkcast |
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.
hi, there is common code in the two sections of code that check for the checkcast I suggest creating a method for the common code
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.
Fixed.
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
@lgxbslgx 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 4 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@vicente-romero-oracle) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
@vicente-romero-oracle Thanks for your review. Could I get your help to sponsor this patch? /integrate |
/sponsor |
sure, done |
@vicente-romero-oracle @lgxbslgx Since your change was applied there have been 4 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit b7ac705. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Hi all,
Before the phase
desugar
, the demo(C1 & I1) o
has one type-cast sub-tree,JCTypeIntersection C1&I1
, at the syntax tree. After the phasedesugar
, the(C1 & I1) o
becomes three type-cast sub-trees:JCTypeIntersection C1&I1
,I1
,C1
. So at phaseGen
,javac
generates threecheckcast
according to the three type-cast sub-trees which causes this bug.This patch doesn't generate
checkcast
when the type isJCTypeIntersection
so that the problem can be solved. And a corresponding test case is added.Another way to solve this issue is that the
TransTypes
of thedesugar
should be modified and two type-cast sub-trees should be generated instead of three. But this way may change more code than my original patch and may cause other regression.Thank you for taking the time to review.
Best Regards.
--Guoxiong
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3399/head:pull/3399
$ git checkout pull/3399
Update a local copy of the PR:
$ git checkout pull/3399
$ git pull https://git.openjdk.java.net/jdk pull/3399/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 3399
View PR using the GUI difftool:
$ git pr show -t 3399
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3399.diff