JDK-8148213 : Regression: nested unchecked call does not trigger erasure of return type
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2016-01-26
  • Updated: 2016-03-10
  • Resolved: 2016-01-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b104Fixed
Related Reports
Relates :  
Description
This program fails to compile after JDK-JDK-8147493:

abstract class Test {

 interface R<E> {}
 interface Q<T> {}
 interface T { <E> Q<E> n(R<E> r); }
 abstract <T> T isA(Class<T> t);
 abstract <T> S<T> w(T t);
 interface S<T> { S<T> t(T value); }

 void f(T t, Q<String> q) {
   w(t.n(isA(R.class))).t(q);
 }
}


error: incompatible types: Q<String> cannot be converted to Q<Object>
   w(t.n(isA(R.class))).t(q);
                          
Comments
I believe the program should be accepted - I've alpha-renamed type-variables in your example to make matters a bit clearer: abstract class Test { interface R<Z> {} interface Q<Y> {} interface T { <N> Q<N> n(R<N> r); } abstract <I> I isA(Class<I> t); abstract <W> S<W> w(W t); interface S<X> { S<X> t(X value); } void f(T t, Q<String> q) { w(t.n(isA(R.class))).t(q); } } The big issue occurs when we call 't.n' - performing applicability inference of its argument means evaluating the expression constraint isA() -> R<N>, and such a constraint should be evaluated by performing invocation type inference (18.5.2). According to 18.5.2, given that isA() returns a bare inference variable ('I') and given that this inference variable has an equality constraints (R) and given that there's no paramaterization of the target type R<N> such that R <: R<N>, eager instantiation of 'I' should occur. Then, following 18.5.2 we should set up a type compatibility constraints of the kind R -> R<N>, and that kind of compatibility constraint clearly generates an unchecked warning (as per 18.2.2). So, popping back, we have found an unchecked warning while proving applicability of 't.n'. This should mean that invocation type-inference for 't.n' we should effectively erase the return type: "If unchecked conversion was necessary for the method to be applicable during constraint set reduction in ��18.5.1, the constraint formula ���|R| ��� T��� is reduced and incorporated with B2." Which should mean W = |Q|, and then W<Q>'s member 't' should have a type (Q)S<Q>, which should be compatible with Q<String>.
26-01-2016