-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
8257037: No javac warning when calling deprecated constructor with diamond #1490
Conversation
👋 Welcome back lgxbslgx! A progress list of the required criteria for merging this PR into |
Webrevs
|
Sorry for closing the PR accidentally. |
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 the fix seems in spirit with respect to what happens for ordinary constructor resolution. I guess there is a question as to whether we should check for these warnings during resolution or after (probably checking for warning after resolution might be a better idea) - as there is some duplication between the code in findConstructor
and the new findDiamond
and what goes on in Attr::checkId
which also check for these warnings (and some more) but doesn't apply checks on constructors.
Just for fun, I tried this patch:
diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
index df21524229c..05d56136000 100644
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
@@ -4459,15 +4459,11 @@ public class Attr extends JCTree.Visitor {
}
// Emit a `deprecation' warning if symbol is deprecated.
- // (for constructors (but not for constructor references), the error
- // was given when the constructor was resolved)
- if (sym.name != names.init || tree.hasTag(REFERENCE)) {
- chk.checkDeprecated(tree.pos(), env.info.scope.owner, sym);
- chk.checkSunAPI(tree.pos(), sym);
- chk.checkProfile(tree.pos(), sym);
- chk.checkPreview(tree.pos(), sym);
- }
+ chk.checkDeprecated(tree.pos(), env.info.scope.owner, sym);
+ chk.checkSunAPI(tree.pos(), sym);
+ chk.checkProfile(tree.pos(), sym);
+ chk.checkPreview(tree.pos(), sym);
// If symbol is a variable, check that its type and
// kind are compatible with the prototype and protokind.
diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
index 727d2989adf..9bb37fc23b8 100644
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
@@ -2859,8 +2859,6 @@ public class Resolve {
names.init, argtypes,
typeargtypes, allowBoxing,
useVarargs);
- chk.checkDeprecated(pos, env.info.scope.owner, sym);
- chk.checkPreview(pos, sym);
return sym;
}
@@ -2937,6 +2935,7 @@ public class Resolve {
return sym;
}
};
+ newConstr.setAttributes(sym);
bestSoFar = selectBest(env, site, argtypes, typeargtypes,
newConstr,
bestSoFar,
This fixes your issues, and removes the warning code duplication between Attr
and Resolve
, as well as adding checks for all the remaining kinds of warnings (sunAPI, deprecation, preview and profile) - although I believe most of those are not as important.
I guess I'll leave you to decide how you want to tackle this. As I said, the patch you wrote remains within the spirit of the original code - my only minor quibble is that this "spirit" is questionable, as it involves issuing same warnings in different places, this enforcing developers to replicate code (and forgetting to do so, as it already happened) in multiple places.
Thank you for the comment and suggestion. I had seen and paid attention to the following code in
These code confused me. Because the comments In order not to generate unknown issues, I chose not to revise these code when being solved this bug. @mcimadamore I test your patch locally by using the following command. All the tests passed.
Your patch is a better solution if no any unknown regression occurs. But I have no idea about the unknown regressions now. Finally, I have a little question.
|
…he redundant warning code
Sorry, that was a leftover from a previous experiment. That's not necessary. We'll run some more tests on our side and I'll let you know. |
@mcimadamore Should I add you as a contributor of this patch? Does it need another reviewer to review if I add you as a contributor? |
As you prefer - I don't mind either way. I don't think adding me as a contributor should prevent the integration, or me being able to sponsor, but I'm not 100% sure. |
/contributor add @mcimadamore |
@lgxbslgx |
I revise the test code based on the comment[1] written by Jonathan Gibbons in JDK-8231622[2].
[1] https://mail.openjdk.java.net/pipermail/compiler-dev/2020-December/015542.html |
The extensive testing revealed at least 10 cases where the compiler is issuing a new, resolution-related error when it wasn't doing so before - (the errors seem to have to do with |
It is a good news that the trouble is found before the integration instead of after the release of JDK16. |
@lgxbslgx Syntax:
|
/contributor remove @mcimadamore |
@lgxbslgx |
Actually, after some more analysis, I discovered that many of the errors were unrelated with your fix - and had to do instead with the addition of a new default method on Stream, which is causing overload resolution changes in code that has static imports on Collectors. Only one issue remains to be fully triaged - but, being annotation related, I think it's unlikely caused by your patch. In other words, I believe both patches are likely to be safe. I'm obviously ok with you going ahead with the more conservative fix, since you already reverted the code to that version. I apologize for the back and forth! |
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 to go
@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 151 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. 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 (@mcimadamore) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/integrate |
Mailing list message from Remi Forax on compiler-dev: oops, R?mi ----- Mail original -----
|
yes - precisely |
/sponsor |
@mcimadamore Only the author (@lgxbslgx) is allowed to issue the |
/sponsor |
@mcimadamore @lgxbslgx Since your change was applied there have been 154 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 2c04fc0. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Hi all,
When calling deprecated constructor with diamond, the compiler doesn't output warning.
The test case is shown below.
This patch solves the bug and adds corresponding test case.
Thank you for taking the time to review.
Best Regards.
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/1490/head:pull/1490
$ git checkout pull/1490