From e55a20cc24268c8b0f42ef4b1aa37448f5cb3d19 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Mar 2014 16:25:06 +0100 Subject: [PATCH] raw substitutor when erasure happened during inference --- .../source/resolve/graphInference/InferenceSession.java | 7 +++++-- .../genericsHighlighting8/Erasure.java | 9 +++++++++ .../daemon/lambda/GenericsHighlighting8Test.java | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/Erasure.java 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 c6c828c9b818..74730b1e94e4 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 @@ -366,7 +366,10 @@ public class InferenceSession { final InferenceVariable inferenceVariable = shouldResolveAndInstantiate(returnType, targetType); if (inferenceVariable != null) { final PsiSubstitutor substitutor = resolveSubset(Collections.singletonList(inferenceVariable), mySiteSubstitutor); - myConstraints.add(new TypeCompatibilityConstraint(targetType, PsiUtil.captureToplevelWildcards(substitutor.substitute(inferenceVariable.getParameter()), myContext))); + final PsiType substitutedReturnType = substitutor.substitute(inferenceVariable.getParameter()); + if (substitutedReturnType != null) { + myConstraints.add(new TypeCompatibilityConstraint(targetType, PsiUtil.captureToplevelWildcards(substitutedReturnType, myContext))); + } } else { if (FunctionalInterfaceParameterizationUtil.isWildcardParameterized(returnType)) { @@ -707,7 +710,7 @@ public class InferenceSession { substitutor = substitutor.put(typeParameter, runtimeException); } else { - substitutor = substitutor.put(typeParameter, getUpperBound(var, substitutor)); + substitutor = substitutor.put(typeParameter, myErased ? null : getUpperBound(var, substitutor)); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/Erasure.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/Erasure.java new file mode 100644 index 000000000000..0d38ade88126 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/Erasure.java @@ -0,0 +1,9 @@ +import java.util.Collection; + +abstract class NCollections { + public void foo(Collection coll) { + bar((Collection)coll); + } + + public abstract > T2 bar(Collection coll); +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java index f1db6fb9c3aa..8cd16f665e67 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java @@ -752,7 +752,9 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase { } public void testSuperWildcardWithBoundPromotion() { doTest();} - + + public void testErasure() throws Exception { doTest(); } + private void doTest() { doTest(false); }