Summary: | Unclear result of calling isAssigmentCompatible for wildcard types | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Dirk Baeumer <dirk_baeumer> |
Component: | Core | Assignee: | Maxime Daniel <maxime_daniel> |
Status: | RESOLVED WORKSFORME | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | markus.kell.r, martinae |
Version: | 3.1 | ||
Target Milestone: | 3.2 M6 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Dirk Baeumer
2005-01-25 10:31:34 EST
Another case: List<? extends Object> lhs; List<? extends Number> rhs; { lhs.add(rhs.get(0)); } procudes compile error. However "? extends Number".isAssignmentCompatible("? extends Object") produces true. This should be false IMO since ? in ? extends Number can be bound to Integer and ? in ? extends Object can be bound to String and Number.isAssignmentCompatible(String) == false; Regarding the case in comment #1. Philippe, I tried your idea: public class A<LHS, RHS> { LHS lhs; RHS rhs; { A<? extends Object, ? extends Number> a= null; a.lhs= a.rhs; } } This produces a compile error saying: Bound mismatch: Cannot assign expression of type ? extends Number to wildcard type ? extends Object. The wildcard type has no lower bound, and may actually be more restrictive than expression type. So "? extends Number".isAssignmentCompatible("? extends Object") should return false then. Indeed. I cannot reproduce the "true" answers from isAssignmentCompatible; using source code. I suspect our API is buggy, since it isn't the true semantics played by the compiler. Can you provide the right testcase you used ? import java.util.List; public class X<U extends Number> { U u; void foo(X<? extends Number> xn, X<? extends U> xu) { xu.u = xn.u; // ko xn.u = xu.u; // ko } } Philippe, the test I use is TypeEnvironmentTests in jdt.ui.tests.refactoring. To enable the wildcard assignment tests go to method TypeEnvironmentTests#performGenericAssignmentTest uncomment the line testAssignment. This will print the result of the comparison to the console together with the result the context wide implementation in the UI computes. You need the code from HEAD to test this. Please reopen if this is still an issue in latest. reopening for closing properly closing, since didn't hear back in a long time. |