new inference: check equals/upper/low bounds consistency

This commit is contained in:
Anna Kozlova
2015-05-29 14:39:29 +02:00
parent 8164a3e4b7
commit 7b0c5b6d05
10 changed files with 44 additions and 49 deletions

View File

@@ -984,16 +984,18 @@ public class InferenceSession {
}
else {
for (PsiType upperType : var.getBounds(InferenceBound.UPPER)) {
if (isProperType(upperType) && !TypeConversionUtil.isAssignable(substitutor.substitute(upperType), lowerBound)) {
final String incompatibleBoundsMessage;
if (type != lowerBound) {
if (isProperType(upperType) ) {
String incompatibleBoundsMessage = null;
if (type != lowerBound && !TypeConversionUtil.isAssignable(substitutor.substitute(upperType), type)) {
incompatibleBoundsMessage = incompatibleBoundsMessage(var, substitutor, InferenceBound.EQ, EQUALITY_CONSTRAINTS_PRESENTATION, InferenceBound.UPPER, UPPER_BOUNDS_PRESENTATION);
}
else {
else if (type == lowerBound && !TypeConversionUtil.isAssignable(substitutor.substitute(upperType), lowerBound)) {
incompatibleBoundsMessage = incompatibleBoundsMessage(var, substitutor, InferenceBound.LOWER, LOWER_BOUNDS_PRESENTATION, InferenceBound.UPPER, UPPER_BOUNDS_PRESENTATION);
}
registerIncompatibleErrorMessage(incompatibleBoundsMessage, var.getParameter());
return PsiType.NULL;
if (incompatibleBoundsMessage != null) {
registerIncompatibleErrorMessage(incompatibleBoundsMessage, var.getParameter());
return PsiType.NULL;
}
}
}
}

View File

@@ -88,10 +88,7 @@ public class SubtypingConstraint implements ConstraintFormula {
}
if (((PsiWildcardType)myS).isExtends()) {
if (sBound instanceof PsiCapturedWildcardType) {
return true;
}
constraints.add(new StrictSubtypingConstraint(tBound, sBound));
constraints.add(new StrictSubtypingConstraint(tBound, sBound instanceof PsiCapturedWildcardType ? ((PsiCapturedWildcardType)sBound).getUpperBound() : sBound));
return true;
}

View File

@@ -7,6 +7,6 @@ abstract class B {
}
void foo(Class<?> aClass) {
A a = <error descr="Inferred type 'capture<?>' for type parameter 'T' is not within its bound; should extend 'A'">getA(aClass)</error>;
A a = getA<error descr="'getA(java.lang.Class<T>)' in 'B' cannot be applied to '(java.lang.Class<capture<?>>)'">(aClass)</error>;
}
}

View File

@@ -7,9 +7,9 @@ class B<T> extends A<A<T>> {
foo(sb);
foo(s);
<error descr="Inferred type 'capture<?>' for type parameter 'T' is not within its bound; should extend 'java.lang.String'">foo1(b)</error>;
foo1<error descr="'foo1(A<A<T>>)' in 'B' cannot be applied to '(B<capture<?>>)'">(b)</error>;
foo1(eb);
<error descr="Inferred type 'capture<? super java.lang.String>' for type parameter 'T' is not within its bound; should extend 'java.lang.String'">foo1(sb)</error>;
foo1<error descr="'foo1(A<A<T>>)' in 'B' cannot be applied to '(B<capture<? super java.lang.String>>)'">(sb)</error>;
foo1(s);
foo2(b);

View File

@@ -35,7 +35,7 @@ class Test {
}
void bug1(Parametrized<? super T> param) {
<error descr="Inferred type 'capture<? super T>' for type parameter 'I' is not within its bound; should extend 'java.lang.Number'">foo(param)</error>;
foo<error descr="'foo(Test.Parametrized<I>)' in 'Test.Bug1' cannot be applied to '(Test.Parametrized<capture<? super T>>)'">(param)</error>;
}

View File

@@ -214,7 +214,7 @@ public static void foo(List<? extends Foo> foos) {
class OtherBug1 {
public static void foo(List<? super Foo> foos) {
final Comparator<Foo> comparator = createComparator();
Collections.sort<error descr="'sort(java.util.List<capture<? super OtherBug1.Foo>>, java.util.Comparator<capture<? super OtherBug1.Foo>>)' in 'java.util.Collections' cannot be applied to '(java.util.List<capture<? super OtherBug1.Foo>>, java.util.Comparator<OtherBug1.Foo>)'">(foos, comparator)</error>;
Collections.sort<error descr="'sort(java.util.List<T>, java.util.Comparator<? super T>)' in 'java.util.Collections' cannot be applied to '(java.util.List<capture<? super OtherBug1.Foo>>, java.util.Comparator<OtherBug1.Foo>)'">(foos, comparator)</error>;
}
private static Comparator<Foo> createComparator() {

View File

@@ -28,7 +28,7 @@ class Test {
public static void main(String[] args) {
IConverter<String> converter = getConverter(String.class);
IConverter<String> converter1 = getConverter1(String.class);
IConverter<String> converter2 = <error descr="Inferred type 'java.lang.String' for type parameter 'C' is not within its bound; should extend 'java.lang.Double'">getConverter2(String.class)</error>;
IConverter<String> converter2 = getConverter2<error descr="'getConverter2(java.lang.Class<C>)' in 'Test' cannot be applied to '(java.lang.Class<java.lang.String>)'">(String.class)</error>;
}
}

View File

@@ -215,7 +215,7 @@ abstract class A<T> {
<K> void baz31(B<K, ? extends K> a) {}
abstract B<T,T> foo31();
void bar31(A<?> a){
baz31<error descr="'baz31(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo31())</error>;
baz31<error descr="'baz31(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo31())</error>;
}
@@ -229,7 +229,7 @@ abstract class A<T> {
<K> void baz33(B<K, ? extends K> a) {}
abstract B<T,T> foo33();
void bar33(A<? extends T> a){
baz33<error descr="'baz33(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? extends T>,capture<? extends T>>)'">(a.foo33())</error>;
baz33<error descr="'baz33(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? extends T>,capture<? extends T>>)'">(a.foo33())</error>;
}
@@ -257,42 +257,42 @@ 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 baz38(B<K, ? extends K> a) {}
abstract B<T,? extends T> foo38();
void bar38(A<? super T> a){
baz38<error descr="'baz38(B<capture<? super T>,? extends capture<? super T>>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? extends capture<? super T>>>)'">(a.foo38())</error>;
baz38<error descr="'baz38(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? extends capture<? super T>>>)'">(a.foo38())</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 baz40(B<K, ? extends K> a) {}
abstract B<T,?> foo40();
void bar40(A<?> a){
baz40<error descr="'baz40(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo40())</error>;
baz40<error descr="'baz40(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo40())</error>;
}
<K> void baz41(B<K, ? extends K> a) {}
abstract B<T,?> foo41();
void bar41(A<? super T> a){
baz41<error descr="'baz41(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<?>>)'">(a.foo41())</error>;
baz41<error descr="'baz41(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<?>>)'">(a.foo41())</error>;
}
<K> void baz42(B<K, ? extends K> a) {}
abstract B<T,?> foo42();
void bar42(A<? extends T> a){
baz42<error descr="'baz42(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? extends T>,capture<?>>)'">(a.foo42())</error>;
baz42<error descr="'baz42(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? extends T>,capture<?>>)'">(a.foo42())</error>;
}
@@ -320,105 +320,105 @@ abstract class A<T> {
<K> void baz46(B<K, ? extends K> a) {}
abstract B<? super T,? extends T> foo46();
void bar46(A<?> a){
baz46<error descr="'baz46(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? super capture<?>>,capture<?>>)'">(a.foo46())</error>;
baz46<error descr="'baz46(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? super capture<?>>,capture<?>>)'">(a.foo46())</error>;
}
<K> void baz47(B<K, ? extends K> a) {}
abstract B<? super T,? extends T> foo47();
void bar47(A<? super T> a){
baz47<error descr="'baz47(B<capture<? super T>,? extends capture<? super T>>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? extends capture<? super T>>>)'">(a.foo47())</error>;
baz47<error descr="'baz47(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? extends capture<? super T>>>)'">(a.foo47())</error>;
}
<K> void baz48(B<K, ? extends K> a) {}
abstract B<? super T,? extends T> foo48();
void bar48(A<? extends T> a){
baz48<error descr="'baz48(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? super capture<? extends T>>,capture<? extends T>>)'">(a.foo48())</error>;
baz48<error descr="'baz48(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? super capture<? extends T>>,capture<? extends T>>)'">(a.foo48())</error>;
}
<K> void baz49(B<K, ? extends K> a) {}
abstract B<? super T,?> foo49();
void bar49(A<?> a){
baz49<error descr="'baz49(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? super capture<?>>,capture<?>>)'">(a.foo49())</error>;
baz49<error descr="'baz49(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? super capture<?>>,capture<?>>)'">(a.foo49())</error>;
}
<K> void baz50(B<K, ? extends K> a) {}
abstract B<? super T,?> foo50();
void bar50(A<? super T> a){
baz50<error descr="'baz50(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<?>>)'">(a.foo50())</error>;
baz50<error descr="'baz50(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<?>>)'">(a.foo50())</error>;
}
<K> void baz51(B<K, ? extends K> a) {}
abstract B<? super T,?> foo51();
void bar51(A<? extends T> a){
baz51<error descr="'baz51(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? super capture<? extends T>>,capture<?>>)'">(a.foo51())</error>;
baz51<error descr="'baz51(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? super capture<? extends T>>,capture<?>>)'">(a.foo51())</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 baz53(B<K, ? extends K> a) {}
abstract B<? extends T,? extends T> foo53();
void bar53(A<? super T> a){
baz53<error descr="'baz53(B<capture<? extends capture<? super T>>,capture<? extends capture<? super T>>>)' in 'A' cannot be applied to '(B<capture<? extends capture<? super T>>,capture<? extends capture<? super T>>>)'">(a.foo53())</error>;
baz53<error descr="'baz53(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? extends capture<? super T>>,capture<? extends capture<? super T>>>)'">(a.foo53())</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 baz55(B<K, ? extends K> a) {}
abstract B<? extends T,?> foo55();
void bar55(A<?> a){
baz55<error descr="'baz55(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo55())</error>;
baz55<error descr="'baz55(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<?>,capture<?>>)'">(a.foo55())</error>;
}
<K> void baz56(B<K, ? extends K> a) {}
abstract B<? extends T,?> foo56();
void bar56(A<? super T> a){
baz56<error descr="'baz56(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? extends capture<? super T>>,capture<?>>)'">(a.foo56())</error>;
baz56<error descr="'baz56(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? extends capture<? super T>>,capture<?>>)'">(a.foo56())</error>;
}
<K> void baz57(B<K, ? extends K> a) {}
abstract B<? extends T,?> foo57();
void bar57(A<? extends T> a){
baz57<error descr="'baz57(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? extends T>,capture<?>>)'">(a.foo57())</error>;
baz57<error descr="'baz57(B<K,? extends K>)' in 'A' cannot be applied to '(B<capture<? extends T>,capture<?>>)'">(a.foo57())</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>;
}
@@ -432,7 +432,7 @@ abstract class A<T> {
<K> void baz62(B<K, ? super K> a) {}
abstract B<T,T> foo62();
void bar62(A<? super T> a){
baz62<error descr="'baz62(B<capture<? super T>,capture<? super T>>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? super T>>)'">(a.foo62())</error>;
baz62<error descr="'baz62(B<K,? super K>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? super T>>)'">(a.foo62())</error>;
}
@@ -1062,7 +1062,7 @@ abstract class A<T> {
<K> void baz152(B<? extends K, ? super K> a) {}
abstract B<T,T> foo152();
void bar152(A<? super T> a){
baz152<error descr="'baz152(B<?,? super java.lang.Object>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? super T>>)'">(a.foo152())</error>;
baz152<error descr="'baz152(B<? extends K,? super K>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? super T>>)'">(a.foo152())</error>;
}
@@ -1083,7 +1083,7 @@ abstract class A<T> {
<K> void baz155(B<? extends K, ? super K> a) {}
abstract B<T,? super T> foo155();
void bar155(A<? super T> a){
baz155<error descr="'baz155(B<?,? super java.lang.Object>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? super T>>)'">(a.foo155())</error>;
baz155<error descr="'baz155(B<? extends K,? super K>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? super T>>)'">(a.foo155())</error>;
}
@@ -1146,7 +1146,7 @@ abstract class A<T> {
<K> void baz164(B<? extends K, ? super K> a) {}
abstract B<? super T,? super T> foo164();
void bar164(A<? super T> a){
baz164<error descr="'baz164(B<?,? super java.lang.Object>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? super T>>)'">(a.foo164())</error>;
baz164<error descr="'baz164(B<? extends K,? super K>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? super T>>)'">(a.foo164())</error>;
}

View File

@@ -49,7 +49,7 @@ class MyTestConstructor {
private static void <warning descr="Private method 'foo(MyTestConstructor.I3)' is never used">foo</warning>(I3 i) {System.out.println(i);}
static {
foo<error descr="Ambiguous method call: both 'MyTestConstructor.foo(I1)' and 'MyTestConstructor.foo(I2)' match">(Foo::new)</error>;
foo<error descr="Cannot resolve method 'foo(<method reference>)'">(Foo::new)</error>;
}
}
@@ -78,6 +78,6 @@ class MyTestMethod {
private static void <warning descr="Private method 'foo(MyTestMethod.I3)' is never used">foo</warning>(I3 i) {System.out.println(i);}
static {
foo<error descr="Ambiguous method call: both 'MyTestMethod.foo(I1)' and 'MyTestMethod.foo(I2)' match">(MyTestMethod::m)</error>;
foo<error descr="Cannot resolve method 'foo(<method reference>)'">(MyTestMethod::m)</error>;
}
}

View File

@@ -16,7 +16,6 @@
package com.intellij.codeInsight.daemon.lambda;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.idea.Bombed;
import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
@@ -24,8 +23,6 @@ import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.IdeaTestUtil;
import org.jetbrains.annotations.NonNls;
import java.util.Calendar;
public class GenericsHighlightingGenerated8Test extends LightDaemonAnalyzerTestCase {
@NonNls private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/genericsHighlightingGenerated8";
@@ -36,7 +33,6 @@ public class GenericsHighlightingGenerated8Test extends LightDaemonAnalyzerTestC
public void testEmptyTestT() throws Exception {}
@Bombed(day = 30, month = Calendar.MAY, year = 2015)
public void testUnrelatedClasses() throws Exception {
doTest();
}