new inference: ignore trivial dependencies

This commit is contained in:
Anna Kozlova
2014-09-01 21:46:10 +04:00
parent 510cdf7355
commit 4d3d6e8a8c
3 changed files with 40 additions and 9 deletions
@@ -17,6 +17,7 @@ package com.intellij.psi.impl.source.resolve.graphInference;
import com.intellij.psi.*;
import com.intellij.psi.impl.light.LightTypeParameter;
import com.intellij.psi.util.PsiUtil;
import java.util.*;
@@ -49,6 +50,10 @@ public class InferenceVariable extends LightTypeParameter {
}
public boolean addBound(PsiType classType, InferenceBound inferenceBound) {
if (inferenceBound == InferenceBound.EQ &&
PsiUtil.resolveClassInClassTypeOnly(classType) == this) {
return false;
}
List<PsiType> list = myBounds.get(inferenceBound);
if (list == null) {
list = new ArrayList<PsiType>();
@@ -77,20 +82,18 @@ public class InferenceVariable extends LightTypeParameter {
}
}
if (!session.hasCapture(this) && dependencies.isEmpty()) {
return dependencies;
}
next:
for (InferenceVariable variable : session.getInferenceVariables()) {
if (!dependencies.contains(variable) && variable != this) {
nextBound:
for (List<PsiType> bounds : myBounds.values()) { //todo
for (List<PsiType> bounds : variable.myBounds.values()) { //todo
if (bounds != null) {
for (PsiType bound : bounds) {
final Set<InferenceVariable> deps = new HashSet<InferenceVariable>();
session.collectDependencies(bound, deps);
if (deps.isEmpty()) {
continue nextBound;
}
if (deps.contains(this)) {
final InferenceVariable inferenceVariable = session.getInferenceVariable(bound);
if (inferenceVariable == this) {
dependencies.add(variable);
continue next;
}
@@ -0,0 +1,27 @@
class ExplicitLambdaNoParams {
interface I<T> {
T a();
}
<F> I<F> foo(I<F> iff) { return null;}
{
foo(() -> foo(() -> 1)).a();
I<Integer> a1 = foo(() -> foo(() -> 1)).a();
}
}
class LambdaWithFormalParameterTypes {
interface I<T> {
T a(int p);
}
<F> I<F> foo(I<F> iff) { return null;}
{
foo((int a) -> foo((int b) -> 1)).a(0);
I<Integer> a1 = foo((int a) -> foo((int b) -> 1)).a(0);
}
}
@@ -94,6 +94,7 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA126109() { doTest(); }
public void testIDEA126809() { doTest(); }
public void testIDEA124424() { doTest(); }
public void testNestedLambdaExpressions1() { doTest(); }
public void testIDEA127596() throws Exception {
doTest();