From 4290a37a08df4ce2e8a2320b183dd847e168a3cb Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Wed, 7 Dec 2016 12:21:37 +0100 Subject: [PATCH] new inference: check intersection type of upper bound to detect substitution (IDEA-165011) --- .../constraints/StrictSubtypingConstraint.java | 10 ++++++++++ .../graphInference/RecursiveTypeWithCapture.java | 10 ++++++++++ .../daemon/lambda/GraphInferenceHighlightingTest.java | 4 ++++ 3 files changed, 24 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/RecursiveTypeWithCapture.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/StrictSubtypingConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/StrictSubtypingConstraint.java index 298228c3f408..bb0d2fe4179f 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/StrictSubtypingConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/StrictSubtypingConstraint.java @@ -20,6 +20,7 @@ import com.intellij.psi.impl.source.resolve.graphInference.InferenceBound; import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession; import com.intellij.psi.impl.source.resolve.graphInference.InferenceVariable; import com.intellij.psi.util.InheritanceUtil; +import com.intellij.psi.util.PsiUtil; import com.intellij.psi.util.TypeConversionUtil; import java.util.HashSet; @@ -135,6 +136,15 @@ public class StrictSubtypingConstraint implements ConstraintFormula { if (upperBound instanceof PsiClassType) { sType = (PsiClassType)upperBound; } + else if (upperBound instanceof PsiIntersectionType) { + for (PsiType type : ((PsiIntersectionType)upperBound).getConjuncts()) { + PsiClass sCandidate = PsiUtil.resolveClassInClassTypeOnly(type); + if (sCandidate != null && InheritanceUtil.isInheritorOrSelf(sCandidate, CClass, true)) { + sType = (PsiClassType)type; + break; + } + } + } } if (sType == null) return false; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/RecursiveTypeWithCapture.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/RecursiveTypeWithCapture.java new file mode 100644 index 000000000000..1fd1113ee321 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/RecursiveTypeWithCapture.java @@ -0,0 +1,10 @@ + +import java.util.List; + +class Test { + void foo(final Enum> f) {} + + void bar(final Enum> e) { + foo(e); + } +} \ 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 b24ba27285bd..7d7f252fb547 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 @@ -495,6 +495,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase doTest(); } + public void testRecursiveTypeWithCapture() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest(false); }