Change in javac generics type inference
Maurizio Cimadamore
Maurizio.Cimadamore at Sun.COM
Fri Feb 6 01:29:49 PST 2009
Hi Martin
thanks for the report - this looks like a javac bug - I've been able to
reproduce it with the following test case:
class Test<X> {
<K extends Test<K>> void m() {}
void test() {
m();
}
}
It seems like this bug has been there for a while - I see you are using
jdk7 b05 and that openjdk6 is also affected, which means that the bug
got in *before* the openjdk6/jdk7 split. At a first sight it looks
vaguely as related to/duplicate of 6369605 , as the problem involves an
uninferred type-variable with a recursive bound - even when this program
used to compie neither javac nor Eclipse used to get this right (kinda
failed silently); perhaps, after some fix, the problem has become more
evident. My current fix for 6369605 seems to solve the problem, which is
a good thing. Bad news is that my fix requires a non trivial spec change
(JLS3 15.12.2.8) and we'll need to go through CCC for fixing that, I'll
definitively look into that.
Thanks again
Maurizio
Martin Buchholz wrote:
> Hi javac maintainers,
>
> We have a program that started to fail to compile as of jdk7-b05
> (openjdk6 is naturally also affected)
>
> I'm not an expert on generics type inference,
> but the code seems reasonable, and used to compile,
> so....bug?
>
> $ cat Bug.java; for java in jdk1.7.0-b04 jdk1.7.0-b05; do echo ---
> $java ---- ; /home/build/static/projects_norep/java/sun-jdk/linux-i586/$java/bin/javac
> Bug.java; done
> public class Bug {
>
> public static <K extends Key<K>, E extends Entity<E, K>> void get(E entity) {}
>
> public interface Entity<E extends Entity<E, K>, K extends Key<K>> {}
>
> public interface Key<K extends Key<K>> {}
>
> public static class EntityImpl implements Entity<EntityImpl, KeyImpl> {}
>
> public static class KeyImpl implements Key<KeyImpl> {}
>
> public static void main(String[] args) {
> EntityImpl e = new EntityImpl();
> get(e);
> }
> }
> --- jdk1.7.0-b04 ----
> --- jdk1.7.0-b05 ----
> Bug.java:15: incompatible types; inferred type argument(s)
> java.lang.Object do not conform to bounds of type variable(s) K
> found : <K>void
> required: void
> get(e);
> ^
> 1 error
>
More information about the compiler-dev
mailing list