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
GH472: substitute and then erasure if unchecked conversion was necessary #477
GH472: substitute and then erasure if unchecked conversion was necessary #477
Conversation
@stephan-herrmann WDYT? |
Welcome to the wonderful world of type inference! :) :) We should be looking at this sentence from JLS 18.5.2.2:
Here For definition of "return type of m's type" see JLS 8.2 which seems to justify our use of Please see how the variant with substitution is specified just above (my emphasis):
You probably saw, that the flag you are modifying is commented "// propagate simulation of Bug JDK_8026527", so any substitution we already apply happens in deliberate violation of JLS, just to conform to buggy I would not like to take responsibility for piling more ad-hoc changes onto this bug-compatibility implementation. As I can see that you have dug quite deep into type inference, I could offer to assist you in working on a few more bugs in this area, which eventually might enable you to take responsibility yourself, if you like. Meanwhile you could also try to interact with Oracle, suggesting that the specification be changed to cover your proposed change (and thus also legalize existing behavior of |
@stephan-herrmann, thank you for providing more context on this issue. I use From your comment, it links to another javac bug https://bugs.openjdk.org/browse/JDK-8135087, that's exactly the same case as my sample, where javac performs substitution on the return type, and then erasing to raw Class.
Dan confirmed this is a javac bug that's inconsistent with spec. Sadly, they marked this as a P4 low priority issue since it's only noticeable in rare use cases and practical impact is low. It has been inactive for 6 years and I don't expect them to take further action in the near future. Given that it only occurs in rare cases, patching this is tolerable to me. And this can help provide a better out-of-the-box experience for those developers coming from javac-based tools such as maven, gradle, and Intellij IDEA. WDYT?
Yes, I'm interested in getting involved in maintaining this area. Recently we're testing the whole out-of-the-box experience of JDT developer tools by using popular Java projects with top stars on GitHub. And type inference is one of the top issues we found, that's why I start to look into this area. I haven't went through all cases yet, more bugs may be created later. You are very expertise in this area and having your guidance to work through these bugs is definitely valuable to me😀. Thank you for stepping up to offer help. |
Thanks for connecting the dots! This increases the confidence that your proposed change is indeed equal to the bug in javac, and thus will not cause bad surprises in other situations.
Perhaps as last steps before merging you could (a) check if JDK-8135087 and friends suggest more extra constitutional substitutions than what you already proposed, and (b) ensure that those code tweaks properly link to the relevant JDK bugs. |
7b2d98d
to
238d162
Compare
Done. Had a look at the relevant issues with JDK-8135087, they all refer to the case of substituting and erasing the return/thrown types for unchecked invocation. I have updated the unit tests to cover the samples mentioned in these JDK issues. |
The failing test cases on |
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 dropped some final nitpick comments. The signature change I'd rank as mandatory, other comments have less urgency. Once addressed that change is ready to go.
....core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
Outdated
Show resolved
Hide resolved
...ore/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java
Outdated
Show resolved
Hide resolved
...ests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
Show resolved
Hide resolved
238d162
to
b37d11b
Compare
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
b37d11b
to
ae4351b
Compare
The comments are addressed. let me know if it's acceptable. |
All looks good now. For future PRs I'd prefer if changes are done as individual commits, so I can easily see the changes. (The "Compare" link also showed unrelated stuff probably due to a rebase on HEAD on your side?). Things will then be cleaned up by "Squash and merge". |
Sure, agree that keeping individual commits is more friendly to code review. |
Signed-off-by: Jinbo Wang jinbwan@microsoft.com
Change-Id: I524ac3308c9a63aa66aab2c8bcaa5fce6f6b5ad6
What it does
Fixes #472
When the code uses some raw types, the compiler will use unchecked conversion to infer their type. The problem with bug 472 is that the return type of the original method
getAndMap
is a type variableT
, erasing a type variable provides nothing. The fix is to substitue the type variable with the relevant parameterized type before doing the erasure.How to test
Author checklist