More type inference changes
Liam Miller-Cushon
cushon at google.com
Wed Feb 3 18:41:40 UTC 2016
I noticed three more javac9 type inference incompatibilities, each of which
only occurs once in the codebase I've been testing against.
1) The following code is rejected by javac9 at head, and accepted by
earlier versions. The first bad revision is 3211.
http://hg.openjdk.java.net/jdk9/dev/langtools/rev/3211
http://bugs.openjdk.java.net/browse/JDK-8147493
abstract class Test {
interface O<A> {}
interface R<B> {}
interface S<C> { S<C> t(C x); }
abstract <D> D a(Class<D> methodCall);
abstract R<Number> g(O<Number> q, String s);
abstract <E> S<E> w(E m);
S<R<Number>> f(R<Number> r) {
return w(g(a(O.class), a(String.class))).t(r);
}
}
error: incompatible types: S<R> cannot be converted to S<R<Number>>
return w(g(a(O.class), a(String.class))).t(r);
^
2) This is also rejected at head, and accepted by earlier versions. The
first bad revision is 3030.
http://hg.openjdk.java.net/jdk9/dev/langtools/rev/3030
http://bugs.openjdk.java.net/browse/JDK-8078093
abstract class Test {
interface One<A> {}
interface Two<B extends Three, C extends Four> {}
interface Three {}
interface Four {}
abstract <D> One<D> h(Class<D> clazz);
abstract void g(One<? extends Two<Three, Four>> x);
void f() {
g(h(Two.class));
}
}
error: incompatible types: One<Two> cannot be converted to One<? extends
Two<Three,Four>>
g(h(Two.class));
^
3) This one is accepted at head, and also by earlier versions. It was
briefly rejected between 3030 and 3109. Was the fix in 3109 deliberate?
First bad revision:
http://hg.openjdk.java.net/jdk9/dev/langtools/rev/3030
https://bugs.openjdk.java.net/browse/JDK-8078093
First good revision:
http://hg.openjdk.java.net/jdk9/dev/langtools/rev/3109
http://bugs.openjdk.java.net/browse/JDK-8067767
abstract class Test {
interface One<G, H extends One<G, H>> {}
abstract <D, E extends One<D, E>> void g(One<D, E> f);
abstract <A> One<A, ?> h();
void f() {
g(h());
}
}
error: method g in class Test cannot be applied to given types;
g(h());
^
required: One<D,E#1>
found: One<Object,CAP#1>
reason: inferred type does not conform to upper bound(s)
inferred: E#2
upper bound(s): One<Object,E#2>,One<Object,<captured wildcard>>
where D,E#1,E#2,<captured wildcard> are type-variables:
D extends Object declared in method <D,E#1>g(One<D,E#1>)
E#1 extends One<D,E#1> declared in method <D,E#1>g(One<D,E#1>)
E#2 extends One<Object,<captured wildcard>>
<captured wildcard> extends One<Object,E#2>
where CAP#1 is a fresh type-variable:
CAP#1 extends One<Object,CAP#1> from capture of ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20160203/45722b77/attachment.html>
More information about the compiler-dev
mailing list