question about applicability inference with wildcards and deferred types

Dan Smith daniel.smith at oracle.com
Fri May 9 15:59:19 UTC 2014


Hi Liam,

Thanks for the test.  This is a bug in the 'containsType' code that I've been looking into recently.  I've added this example to the comments.

Report is here: https://bugs.openjdk.java.net/browse/JDK-8039214

—Dan

On May 6, 2014, at 12:18 PM, Liam Miller-Cushon <cushon at google.com> wrote:

> I encountered an example where javac8 can't perform applicability inference for a method in the presence of wildcards. This only occurs with -source 8 -target 8. I think it is related to JDK-7177387, since the behaviour goes away when Source.allowPoly() is disabled.
> 
> Here's the code:
> 
> ===
> import java.util.List;
> 
> abstract class Test {
>   abstract <T> List<T> copyOf(List<? extends T> lx);
>   abstract <E> List<E> filter(List<E> lx);
> 
>   // This works:
>   <U> void f(List<U> lx) {
>     copyOf(filter(lx));
>   }
> 
>   // This doesn't:
>   void g(List<?> lx) {
>     copyOf(filter(lx));
>   }
> }
> ===
> 
> The interesting bit of the error message is:
> 
> error: method copyOf in class Test cannot be applied to given types;
> ...
> List<CAP#2> cannot be converted to List<? extends CAP#2>
> 
> I think that the logic in Types.containsType could be improved to handle this case better. Turning on the debug output (Types.debugContainsType) reveals that javac is checking:
> 
> does "? extends capture#630 of ?" contain "capture#630 of ?" ?
> => U(capture#630 of ?) <: U(? extends capture#630 of ?)
> => java.lang.Object <: capture#630 of ?
> => false
> 
> My theory is that prior to javac8 the inferencer did not encounter wildcards whose bound was a captured wildcard (? extends CAP of ?), and that changed with the addition of deferred types in JDK-7177387. Perhaps some additional logic could be added to containsType(T, S) to deal with S being the upper bound of T?
> 
> Thanks,
> Liam
> 



More information about the compiler-dev mailing list