new inference:

reject inference if lower and equals bounds do not agree;
 -> inference variable should fill extends list types with it's upper bounds as they are correctly substituted with session's inference variables, otherwise incorporation up-up rule could get refs to initial type parameter instead of correct inference variable
This commit is contained in:
Anna Kozlova
2015-02-19 18:07:54 +01:00
parent abdd8b2d52
commit 7bdb789b45
7 changed files with 65 additions and 51 deletions
@@ -2,6 +2,6 @@ class A<T> {
<T extends A<T>> void foo(T x){}
void bar(A<?> x){
<error descr="Inferred type 'java.lang.Object' for type parameter 'T' is not within its bound; should extend 'A<java.lang.Object>'">foo(x)</error>;
foo<error descr="'foo(T)' in 'A' cannot be applied to '(A<capture<?>>)'">(x)</error>;
}
}
@@ -4,45 +4,45 @@ abstract class A<T> {
<K> void baz37(B<K, ? extends K> a) {}
abstract B<T,? extends T> foo37();
void bar37(A<?> a){
baz37<error descr="'baz37(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo37())</error>;
baz37<error descr="'baz37(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo37())</error>;
}
<K> void baz39(B<K, ? extends K> a) {}
abstract B<T,? extends T> foo39();
void bar39(A<? extends T> a){
baz39<error descr="'baz39(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? extends T>,capture<? extends T>>)'">(a.foo39())</error>;
baz39<error descr="'baz39(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? extends T>,capture<? extends T>>)'">(a.foo39())</error>;
}
<K> void baz52(B<K, ? extends K> a) {}
abstract B<? extends T,? extends T> foo52();
void bar52(A<?> a){
baz52<error descr="'baz52(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo52())</error>;
baz52<error descr="'baz52(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo52())</error>;
}
<K> void baz54(B<K, ? extends K> a) {}
abstract B<? extends T,? extends T> foo54();
void bar54(A<? extends T> a){
baz54<error descr="'baz54(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? extends T>,capture<? extends T>>)'">(a.foo54())</error>;
baz54<error descr="'baz54(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? extends T>,capture<? extends T>>)'">(a.foo54())</error>;
}
<K> void baz58(B<K, ? extends K> a) {}
abstract B<?,?> foo58();
void bar58(A<?> a){
baz58<error descr="'baz58(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo58())</error>;
baz58<error descr="'baz58(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo58())</error>;
}
<K> void baz59(B<K, ? extends K> a) {}
abstract B<?,?> foo59();
void bar59(A<? super T> a){
baz59<error descr="'baz59(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo59())</error>;
baz59<error descr="'baz59(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo59())</error>;
}
<K> void baz60(B<K, ? extends K> a) {}
abstract B<?,?> foo60();
void bar60(A<? extends T> a){
baz60<error descr="'baz60(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo60())</error>;
baz60<error descr="'baz60(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo60())</error>;
}
}
@@ -142,7 +142,7 @@ class S1 {
}
void bar(List<? extends S1> k) {
f<error descr="'f(java.util.List<java.lang.Object>, java.lang.Object)' in 'S1' cannot be applied to '(java.util.List<capture<? extends S1>>, S1)'">(k, k.get(0))</error>;
f<error descr="'f(java.util.List<T>, T)' in 'S1' cannot be applied to '(java.util.List<capture<? extends S1>>, S1)'">(k, k.get(0))</error>;
}
}
@@ -3,5 +3,5 @@ import java.util.Map;
class SOE {
public static <K extends M, M extends Map<K,M>> M foo() {return null;}
public static <K1 extends M1, M1 extends Map<K1,M1>> Map<K1, M1> foo1() {<error descr="Incompatible types. Found: 'M', required: 'java.util.Map<K1,M1>'">return foo();</error>}
public static <K1 extends M1, M1 extends Map<K1,M1>> Map<K1, M1> foo1() {return foo();}
}