eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
164 stars 130 forks source link

Potential type inference issue #1313

Open uhoefel opened 1 year ago

uhoefel commented 1 year ago

Given a method like this:

public static final <T> Class<T> foo(Collection<? extends Class<? extends T>> classes) {
    return null;
}

with jshell I can do this:

jshell> Class<Object[]> x = foo(List.of(double[][].class, Long[][].class));
x ==> null

while with eclipse I get this: image

Note that for double[][] --> Double[][] it correctly infers Number[][].

stephan-herrmann commented 1 year ago

This works in both javac and ecj:

    List<Class<? extends Object[]>> list = List.of(double[][].class, Long[][].class);
    Class<Object[]> x = foo(list);

This, too, fails in ecj only:

    var list = List.of(double[][].class, Long[][].class);
    Class<Object[]> x = foo(list);

saying:

        Class<Object[]> x = foo(list);
                            ^^^^^^^^^
Type mismatch: cannot convert from Class<Object & Serializable & Cloneable> to Class<Object[]>

The difference cannot be observed, when removing one array dimension in every type involved:

static void z() {
    var list = List.of(double[].class, Long[].class);
    Class<Object> x = foo(list);
}