"var" type inferrence bug with generic wrapping#5054
Conversation
|
@srikanth-sankaran fyi I organized the changes as 3 commits for easier reviewing, in case you find the time for it. commit 1 brings the main change in TypeSystem.getWildcard(), where we simply drop "extends Object". In this commit I adjusted tests only where we expected error messages with "? extends Object", which in many cases is no longer shown. Only for one error message I restore that information from the AST. commit 2 resolves all remaining failures in GenericTypeTest, where changes were indeed significant, but AFAICS all changes are going towards alignment with javac. This is the part that might deserve special scrutiny, but running this test class with commit 3 finally restores nullness information from |
ccd3a1e to
8c812e2
Compare
I'll wait for the test failures to be cleaned up and then review - OK ? Thanks |
|
Test failures revealed that curiously our jclMinXY.jar declare |
OK, test failures have been resolved. I only need to remove a now-obsolete @jarthana since this is a fundamental change it would be great to have this change stress tested. If possible with imposing stress on you :) I'd like to merge this for M3. |
Previously, we suppressed this warning: Inside A second warning was but that one is tightly coupled to the former warning via code Interestingly, javac is reporting the second warning but not the first: I doubt the usefulness of that warning, though, since no part of the code should make any assumptions based on the inferred |
+ Ignore type bound of "? extends Object" + Globally change expected errors from "? extends Object" to "?" + Changes in AnnotatableTypeSystem are a placeholder for now Fixes eclipse-jdt#5028
+ in some cases reduce expected errors to those expected also by javac + remove unused excuses run.javac score of this test class: 1.8: 7 fails, previously 8 9: 10 fails, previously 14 26: 13 fails, previously 18
+ 1 case in tests.compiler.parser + many occurrences of Class<? extends Object> in completion tests + use more specific bound where bound is relevant for the test Code change for ExternalAnnotations18Test.testBug508955b(): + normalize eea signature to fold +Ljava/lang/Object; to * + encode variants with null annotations as *1 or *0 resp.
0368883 to
d525bdb
Compare
Looks good. |
srikanth-sankaran
left a comment
There was a problem hiding this comment.
I have made one pass over the changes. Code changes received close attention while test changes were only glanced through. I will closely scrutinize the test changes tomorrow.
This worries me somewhat - I haven't fully investigated it. My worry is about any ripple effects around not detecting an unchecked conversion. As I recall there are various clauses in the JLS that stipulate different behavior based on whether an unchecked cast was involved. Don't have a ready reference though. I'll trust your intuition here. If raw types were not in the picture, the warning would go away even with javac ? That would mitigate my worries a whole lot. |
| List is a raw type. References to generic type List<E> should be parameterized | ||
| ---------- | ||
| """); | ||
| } |
There was a problem hiding this comment.
As commented in #5054 (comment) the difference in warning behavior worries me a bit - I will go with your analysis and intuition here.
| "5. WARNING in X.java (at line 18)\n" + | ||
| " mx1.foo(mx2.get());\n" + | ||
| " ^^^^^^^^^\n" + | ||
| "Type safety: The expression of type Class needs unchecked conversion to conform to Class<? extends Object>\n" + |
There was a problem hiding this comment.
This is what you allude to in the top half of #5054 (comment) I believe. Looks good.
| "Unnecessary cast from Class to Class<?>\n" + | ||
| "----------\n" + | ||
| "3. WARNING in X.java (at line 9)\n" + | ||
| " final Class<? extends String> clazz2 = (Class<? extends String>) classes.get(\"test\");\n" + |
There was a problem hiding this comment.
Diagnostics skip from 1 to 3 ... I have seen this before that such jumps don't cause test failures. If you have other changes, fix this one too along with it.
There was a problem hiding this comment.
I found it kind of cute, that this is tolerated, allowing us to minimize the diff. :)
OTOH, I agree that this looks confusing now.
| " lhs = rhs; // 3\n" + | ||
| " ^^^\n" + | ||
| "Type mismatch: cannot convert from X<X<? extends Object>> to X<X<? extends Runnable>>\n" + | ||
| */ |
There was a problem hiding this comment.
Do you plan to raise this with the OpenJDK team ?
There was a problem hiding this comment.
Yea, I probably should. Reduced test:
public abstract class X<T extends Runnable> implements Runnable {
void foo1(X<X<? extends Runnable>> lhs, X<X<? extends Object>> rhs) {
lhs = rhs;
}
void foo2(X<X<? extends Runnable>> lhs, X<X<?>> rhs) {
lhs = rhs;
}
}Should in any way report an even number or errors, but:
- ecj: 0
- javac: 1
| "Type mismatch: cannot convert from X<X<? extends Object>> to X<X<? extends Runnable>>\n" + | ||
| */ | ||
| "----------\n" + | ||
| "4. ERROR in X.java (at line 19)\n" + |
There was a problem hiding this comment.
Nit: Diagnostics number is not sequential
srikanth-sankaran
left a comment
There was a problem hiding this comment.
Overall looks good.
- A couple of minor comments about diagnostics not being sequential. Since these seem tolerated, you may ignore them unless you are also considering other changes.
- A question about follow up with javac folk on behavior.
- Please double check once again to satisfy yourself that what is documented in #5054 (comment) is all well (I have no definite problem to report here)
|
I ran a query to pull up all open github tickets that contain the string "extends Object" somewhere in the body. Here is the result. At leisure you may want to see if any of them change behavior due to the fix here, hopefully in the right direction. |
Please note that javac does not report unchecked conversion but unchecked invocation. I would expect this warning to be specified somewhere in JLS 15.12 but so far I found nothing in this direction. While I was deep into arguing that there is no reason for any warning I found something worth further investigation -> #5062. Back to the issue at hand, however, we have
I see no reason for any warning, pending the result of discussing #5062.
Right, replacing both instances of |
Thanks, this is very helpful. For some anecdotal reference I found in an email as early as Feb 2014:
:-/ |
Thanks for your diligence!
Since no further changes are planned I'll leave it at this. I noted, though, that in the future I will prefer contiguous numbering over minimal test changes.
Noted, will do. Perhaps after scanning your list of "extends Object" issues.
For the case at hand I argue that no harm is done, while a more general question has been out sourced to #5062 Based on the approval, the only thing left to do is coordination regarding eclipse-platform/eclipse.platform.ui#3992 |
No changes found in any of those examples. Actually, there was hardly any mention of |
|
@stephan-herrmann : FYI: one jdt ui test needs expectation update: |
React to change from eclipse-jdt/eclipse.jdt.core#5054 Fixes #2982
Fixes #5028
Fixes #2857