From 2be1c64a13c7f72e4ac40ee36caf4dd28935f1b5 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 28 Dec 2015 16:31:05 +0100 Subject: [PATCH] new inference: correct capture incorporation (IDEA-149807) --- .../InferenceIncorporationPhase.java | 2 +- .../resolve/graphInference/InferenceSession.java | 2 +- .../constraints/StrictSubtypingConstraint.java | 1 + .../lambda/graphInference/CaptureConstraint.java | 15 +++++++++++++++ .../lambda/GraphInferenceHighlightingTest.java | 4 ++++ 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/CaptureConstraint.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java index f9518571414c..b120d5dfac12 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java @@ -167,7 +167,7 @@ public class InferenceIncorporationPhase { for (PsiType lowerBound : lowerBounds) { if (mySession.getInferenceVariable(lowerBound) == null) { - addConstraint(new StrictSubtypingConstraint(lowerBound, superBound)); + addConstraint(new StrictSubtypingConstraint(superBound, lowerBound)); } } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index bf9e498deeac..a748d3aacd3e 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -674,7 +674,7 @@ public class InferenceSession { } substitutedCapture = elementFactory.createType(psiClass, newParameters); - myIncorporationPhase.addCapture(copy, substitutedCapture); + myIncorporationPhase.addCapture(copy, (PsiClassType)returnType); addConstraint(new TypeCompatibilityConstraint(targetType, substitutedCapture)); } } else { 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 a198108dad9e..63b1d3eba800 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 @@ -32,6 +32,7 @@ public class StrictSubtypingConstraint implements ConstraintFormula { private PsiType myS; private PsiType myT; + //t < s public StrictSubtypingConstraint(PsiType t, PsiType s) { myT = t; myS = s; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/CaptureConstraint.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/CaptureConstraint.java new file mode 100644 index 000000000000..278eef71a063 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/CaptureConstraint.java @@ -0,0 +1,15 @@ + +import java.util.List; + +class Main { + static List foo() { + return get (); + } + + static List get() { + return null; + } + + static class Base {} + static class Child extends Base {} +} 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 61534eecad63..a2705496f2b7 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 @@ -347,6 +347,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase doTest(); } + public void testCaptureConstraint() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest(false); }