Inference of recursive types

Liam Miller-Cushon cushon at google.com
Fri Feb 21 11:31:04 PST 2014


+lambda-dev

Any thoughts on this?

This affects a significant amount of code, and the fact that it only
appears when compiling java 7 with javac8 makes it look like a regression.

The following is a less contrived example of code with recursive types that
doesn't currently compile with javac8 -source 7 -target 7:

class Test {
  <T extends Enum<T>> T getEnum() { return null; }
  <U extends Enum<U>> void m() {
    U e = getEnum();
  }
}

$ javac -source 7 -target 7 Test.java
Test.java:4: error: incompatible types: inference variable T#1 has
incompatible upper bounds Enum<T#2>,U
    U e = getEnum();
                 ^
  where T#1,T#2,U are type-variables:
    T#1 extends Enum<T#1> declared in method <T#1>getEnum()
    T#2 extends U
    U extends Enum<U> declared in method <U>m()

On Fri, Feb 14, 2014 at 5:07 PM, Liam Miller-Cushon <cushon at google.com>wrote:

> Hi -
>
> Sorry if this has already been discussed, but I ran into a difference in
> behaviour between javac8 -source 7/-target 7 and both javac7 and javac8
> -source 8/-target 8.
>
> The following program compiles with everything except javac8 -source
> 7/-target 7.
>
> Is this an intentional change? Having to make g's type parameter explicit
> feels like a regression.
>
> ===
> class Test {
>   static class One<T> {}
>   static class Two extends One<Two> {}
>
>   <T extends One<T>> T f(T a, String s) {
>     T t = g(s);
>     return t;
>   }
>   static <U extends One<U>> U g(String s) {
>     throw new RuntimeException();
>   }
> }
> ===
>
> Test.java:6: error: incompatible types: inference variable U#1 has
> incompatible upper bounds One<U#2>,T
>     T t = g(s);
>            ^
>   where U#1,U#2,T are type-variables:
>     U#1 extends One<U#1> declared in method <U#1>g(String)
>     U#2 extends T
>     T extends One<T> declared in method <T>f(T,String)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20140221/07d8273c/attachment.html 


More information about the compiler-dev mailing list