eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
166 stars 131 forks source link

[type inference] Type mismatch: cannot convert error - javac compiles #2238

Open mpalat opened 7 months ago

mpalat commented 7 months ago

Test case to reproduce:

interface V<T> {}
abstract class A<T> implements V<T> {
    public static <T> A<T> getA(T value) {
        return null;
    }
}

interface J {}
interface K<T, U extends J>  {
    X foo();
}
// javac compiles while ecj gives the following error
public class X {
      public A<K<X, ?>> bar() {
          return A.getA( // ERROR: Type mismatch: cannot convert from A<new K(){}> to A<K<X,?>>
              new K() {
                @Override
                public X foo() {
                  return null;
                }
              });
        }
}

ecj throws "ERROR: Type mismatch: cannot convert from A<new K(){}> to A<K<X,?>>"

@srikanth-sankaran could you please have a quick look if time permits? thanks

stephan-herrmann commented 7 months ago

tiny fix:

-             new K() {
+             new K<>() {

And voilá ecj accepts.

I suggest not to spend much time on differences between javac and ecj when raw types are involved.

srikanth-sankaran commented 4 months ago

tiny fix:

-           new K() {
+           new K<>() {

And voilá ecj accepts.

I suggest not to spend much time on differences between javac and ecj when raw types are involved.

I agree. While it is not directly coupled to https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2536 - perhaps we should simultaneously institute a policy that tickets involving raw types would not be acted upon