| Summary: | [quick assist] Wrong type inferred by assign to new local variable | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | KOVÁCS, István <ikovacs> |
| Component: | UI | Assignee: | Markus Keller <markus.kell.r> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | ikovacs, manju656, markus.kell.r, martinae, philippe_mulet |
| Version: | 3.3.1 | ||
| Target Milestone: | 4.4 M7 | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
| Bug Depends on: | 218645 | ||
| Bug Blocks: | |||
Forgot to include in the original report - if you have a method in NumberThing:
T m1() {
return null;
}
Invoking the assign to new local variable quickfix on
questionmarkThing.m1();
gives you
Object m1 = questionmarkThing.m1();
instead of
Number m1 = questionmarkThing.m1();
Martin - is this you or us ? Could be an issue related to a missing capture. Filed bug 218645 for a problem with ITypeBinding#getTypeBounds(). The fix for this bug will go into Bindings#normalizeTypeBinding(..) and #normalizeForDeclarationUse(..). Need to check other clients of these methods. Maybe we have to keep the old methods and add new utility methods for some of the callers. This becomes more and more important with all the type inference that's used by Java 8's lambda expressions. Fixed with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=bde76c7ffed680bfda8eaca694124e585f592522 Need to add tests for all the get(0) expressions here: class Gen<E extends List<String> & RandomAccess> extends ArrayList<E> { void foo() { Gen<?> g = new Gen<>(); g.get(0); Gen<? extends Cloneable> ge = new Gen<>(); ge.get(0); Gen<? super Vector<String>> gs = new Gen<>(); gs.get(0); } } Tests released to BETA_JAVA8 and master with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=e5ad6393fc711135c738e24711150f7b451e535d (In reply to Manju Mathew from comment #6) > Tests released to BETA_JAVA8 and master with This has been reverted (added to wrong test class), and can be re-released to master once the Java 8 swirl is over. Tests added to AssistQuickFixTest and is released to master with : http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=82b657350491d4b7f81199528d86896b169f1b17 |
If type parameter is ?, quickfix ignores bounds placed on it. Below it is known that T is a subtype of Number, therefore ArrayList<T>.get() returns a Number, yet the quickfix offers the type Object. The code compiles with both Eclipse and javac (1.6.0_03). Version: 3.3.0 Build id: I20070621-1340 import java.util.ArrayList; public class NumberThing<T extends Number> extends ArrayList<T> { void test() { NumberThing<?> questionmarkThing = new NumberThing<Double>(); // produced by 'Assign statement to new local variable' Object object = questionmarkThing.get(0); // although this is valid, too Number n = questionmarkThing.get(0); } }