diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java index 1443eeccbf19..f2fe9f87d2e1 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java @@ -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.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; import org.jetbrains.annotations.NotNull; @@ -150,7 +151,12 @@ public class InferenceVariable extends LightTypeParameter { @Override public boolean isEquivalentTo(PsiElement another) { - return this == another || getDelegate() == another; + if (this == another) return true; + + if (getDelegate() == another && myContext != null && !PsiTreeUtil.isAncestor(((PsiTypeParameter)another).getOwner(), myContext, false)) { + return true; + } + return false; } @Override @@ -163,6 +169,11 @@ public class InferenceVariable extends LightTypeParameter { return getDelegate().toString(); } + @Override + public PsiTypeParameterListOwner getOwner() { + return null; + } + public PsiElement getCallContext() { return myContext; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/RecursiveCallsWithNestedInference.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/RecursiveCallsWithNestedInference.java new file mode 100644 index 000000000000..d38d5588972d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/RecursiveCallsWithNestedInference.java @@ -0,0 +1,35 @@ +import java.util.*; +import java.util.stream.Collectors; + +class Test { + private List bar(List list) { + return null; + } + + private List> foo(List l) { + foo(bar(l)); + final List> perms = foo(null); + return null; + } + + public static List pipe(E head, List tail) { + List newList = new ArrayList<>(tail); + newList.add(0, head); + return newList; + } + public static List subtract(List list, E e) { + List newList = new ArrayList<>(list); + newList.remove(e); + return newList; + } + public static List> perms(List l) { + return l.isEmpty() + ? Collections.singletonList(Collections.emptyList()) + : l.stream().flatMap(h -> perms(subtract(l, h)).stream() + .map(t -> pipe(h, t))).collect(Collectors.toList()); + } + + public static void main(String[] args) { + System.out.println(perms(Arrays.asList("a", "b", "c"))); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java index 2decfac0b681..5f049b61decb 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java @@ -319,6 +319,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase doTest(); } + public void testRecursiveCallsWithNestedInference() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest(false); }