new inference: check provided lower bounds on type parameters, in case of fresh variables they declare the type hierarchy and otherwise constrains won't agree (IDEA-153642)

This commit is contained in:
Anna.Kozlova
2016-03-29 16:51:50 +02:00
parent 5d59c19733
commit f139c4cef4
3 changed files with 32 additions and 16 deletions
@@ -42,24 +42,22 @@ public class JavaClassSupersImpl extends JavaClassSupers {
@NotNull GlobalSearchScope scope,
@NotNull PsiSubstitutor derivedSubstitutor) {
if (InheritanceImplUtil.hasObjectQualifiedName(superClass)) return PsiSubstitutor.EMPTY;
if (!(derivedClass instanceof PsiTypeParameter)) {
List<PsiType> bounds = null;
if (superClass instanceof InferenceVariable) {
bounds = ((InferenceVariable)superClass).getBounds(InferenceBound.LOWER);
List<PsiType> bounds = null;
if (superClass instanceof InferenceVariable) {
bounds = ((InferenceVariable)superClass).getBounds(InferenceBound.LOWER);
}
else if (superClass instanceof PsiTypeParameter) {
final PsiType lowerBound = superClass.getUserData(InferenceSession.LOWER_BOUND);
if (lowerBound != null) {
bounds = Collections.singletonList(lowerBound);
}
else if (superClass instanceof PsiTypeParameter) {
final PsiType lowerBound = superClass.getUserData(InferenceSession.LOWER_BOUND);
}
if (bounds != null) {
for (PsiType lowerBound : bounds) {
if (lowerBound != null) {
bounds = Collections.singletonList(lowerBound);
}
}
if (bounds != null) {
for (PsiType lowerBound : bounds) {
if (lowerBound != null) {
final PsiSubstitutor substitutor = processLowerBound(lowerBound, derivedClass, scope, derivedSubstitutor);
if (substitutor != null) {
return substitutor;
}
final PsiSubstitutor substitutor = processLowerBound(lowerBound, derivedClass, scope, derivedSubstitutor);
if (substitutor != null) {
return substitutor;
}
}
}
@@ -0,0 +1,14 @@
import java.util.List;
import java.util.function.Supplier;
class Test<K> {
{
Supplier<List<? super K>> s = Test::foo;
}
static <E> List<? super E> foo() {
return null;
}
}
@@ -502,6 +502,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testFreshVariableLowerBoundsDuringSuptypeChecks() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}