mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
new inference: reject contradicting equals bounds
This commit is contained in:
+7
-2
@@ -17,6 +17,7 @@ package com.intellij.psi.impl.source.resolve.graphInference;
|
||||
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
@@ -890,7 +891,7 @@ public class InferenceSession {
|
||||
return composeBound(var, InferenceBound.EQ, new Function<Pair<PsiType, PsiType>, PsiType>() {
|
||||
@Override
|
||||
public PsiType fun(Pair<PsiType, PsiType> pair) {
|
||||
return pair.first; //todo check if equals
|
||||
return !Comparing.equal(pair.first, pair.second) ? null : pair.first;
|
||||
}
|
||||
}, substitutor);
|
||||
}
|
||||
@@ -916,7 +917,11 @@ public class InferenceSession {
|
||||
lub = lowerBound;
|
||||
}
|
||||
else {
|
||||
lub = fun.fun(Pair.create(lub, lowerBound));
|
||||
final Pair<PsiType, PsiType> pair = Pair.create(lub, lowerBound);
|
||||
lub = fun.fun(pair);
|
||||
if (lub == null) {
|
||||
return PsiType.NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ class B<L> {
|
||||
void bar(B<?> b, A<?, ?> foo1) {
|
||||
baz(b.foo());
|
||||
A<?, ?> foo = b.foo();
|
||||
baz<error descr="'baz(A<capture<?>,capture<?>>)' in 'B' cannot be applied to '(A<capture<?>,capture<?>>)'">(foo)</error>;
|
||||
baz<error descr="'baz(A<capture<?>,capture<?>>)' in 'B' cannot be applied to '(A<capture<?>,capture<?>>)'">(foo1)</error>;
|
||||
baz<error descr="'baz(A<java.lang.Object,java.lang.Object>)' in 'B' cannot be applied to '(A<capture<?>,capture<?>>)'">(foo)</error>;
|
||||
baz<error descr="'baz(A<java.lang.Object,java.lang.Object>)' in 'B' cannot be applied to '(A<capture<?>,capture<?>>)'">(foo1)</error>;
|
||||
}
|
||||
|
||||
<K> void baz(A<K, K> a) {
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ class SortTest<R extends Comparable<R>> implements Comparable<SortTest<R>> {
|
||||
list.add(t1);
|
||||
SortTest<?> t2 = new SortTest<Integer>(0);
|
||||
list.add(t2);
|
||||
<error descr="Inferred type 'SortTest<?>' for type parameter 'T' is not within its bound; should implement 'java.lang.Comparable<? super SortTest<?>>'">Collections.sort(list)</error>;
|
||||
<error descr="Inferred type 'java.lang.Object' for type parameter 'T' is not within its bound; should implement 'java.lang.Comparable<? super java.lang.Object>'">Collections.sort(list)</error>;
|
||||
t1.compareTo<error descr="'compareTo(SortTest<capture<? extends java.lang.Comparable<capture<?>>>>)' in 'SortTest' cannot be applied to '(SortTest<capture<?>>)'">(t2)</error>;
|
||||
|
||||
//this should be OK
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
class B<T1,S> {}
|
||||
abstract class A<T> {
|
||||
<K> void baz35(B<K, ? extends K> a) {}
|
||||
abstract B<T,? super T> foo35();
|
||||
void bar35(A<? super T> a){
|
||||
baz35<error descr="'baz35(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? super T>>)'">(a.foo35())</error>;
|
||||
}
|
||||
|
||||
|
||||
<K> void baz44(B<K, ? extends K> a) {}
|
||||
abstract B<? super T,? super T> foo44();
|
||||
void bar44(A<? super T> a){
|
||||
baz44<error descr="'baz44(B<java.lang.Object,?>)' in 'A' cannot be applied to '(B<capture<? super T>,capture<? super T>>)'">(a.foo44())</error>;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -47,7 +47,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<java.lang.Number>)' in 'Test.Bug2' cannot be applied to '(Test.Parametrized<capture<? super T>>)'">(param)</error>;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -152,7 +152,7 @@ class S2 {
|
||||
}
|
||||
|
||||
void bar(List<? extends S2> k) {
|
||||
f<error descr="'f(java.util.List<capture<? extends S2>>, java.util.List<capture<? extends S2>>)' in 'S2' cannot be applied to '(java.util.List<capture<? extends S2>>, java.util.List<capture<? extends S2>>)'">(k, k)</error>;
|
||||
f<error descr="'f(java.util.List<java.lang.Object>, java.util.List<java.lang.Object>)' in 'S2' cannot be applied to '(java.util.List<capture<? extends S2>>, java.util.List<capture<? extends S2>>)'">(k, k)</error>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ class S3 {
|
||||
}
|
||||
|
||||
void bar(Map<? extends S3, ? extends S3> k) {
|
||||
f<error descr="'f(java.util.Map<capture<? extends S3>,capture<? extends S3>>)' in 'S3' cannot be applied to '(java.util.Map<capture<? extends S3>,capture<? extends S3>>)'">(k)</error>;
|
||||
f<error descr="'f(java.util.Map<java.lang.Object,java.lang.Object>)' in 'S3' cannot be applied to '(java.util.Map<capture<? extends S3>,capture<? extends S3>>)'">(k)</error>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -780,6 +780,10 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testRejectContradictingEqualsBounds() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user