From ab1d2768b6812b9ce794abd093d7902d752ce8f8 Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 30 Aug 2011 14:59:16 +0200 Subject: [PATCH] diamonds: do not capture wildcard on inference (IDEA-73689 ) --- .../advHighlighting7/DiamondMisc.java | 23 +++++++++++++++++-- .../src/com/intellij/psi/PsiDiamondType.java | 13 +---------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java index 0010a24765a5..aaeb12820ac8 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java @@ -97,14 +97,14 @@ interface I { class FI1 { I i1 = new I<>() { @Override - public String m() { + public String m() { return null; } }; I i2 = new I<>() { @Override - public Object m() { + public Object m() { return null; } }; @@ -152,4 +152,23 @@ class ParenthTest { ParenthTest x = (new ParenthTest<>(null)); //red code is here return 1; } +} + +class TestWildcardInference { + interface A { + } + + class B implements A { + B(C v) { + } + } + + class C {} + + class U { + void foo() { + C x = null; + A y = new B<>(x); + } + } } \ No newline at end of file diff --git a/java/openapi/src/com/intellij/psi/PsiDiamondType.java b/java/openapi/src/com/intellij/psi/PsiDiamondType.java index d857cb120e8f..64ef616d2e50 100644 --- a/java/openapi/src/com/intellij/psi/PsiDiamondType.java +++ b/java/openapi/src/com/intellij/psi/PsiDiamondType.java @@ -295,18 +295,7 @@ public class PsiDiamondType extends PsiType { if (myErrorMessage != null) { return PsiType.EMPTY_ARRAY; } - final PsiType[] result = new PsiType[myInferredTypes.size()]; - for (int i = 0, myInferredTypesSize = myInferredTypes.size(); i < myInferredTypesSize; i++) { - PsiType inferredType = myInferredTypes.get(i); - if (inferredType instanceof PsiWildcardType) { - final PsiType bound = ((PsiWildcardType)inferredType).getBound(); - result[i] = bound != null ? bound : PsiType.getJavaLangObject(PsiManager.getInstance(myProject), GlobalSearchScope.allScope(myProject)); - } - else { - result[i] = inferredType; - } - } - return result; + return myInferredTypes.toArray(new PsiType[myInferredTypes.size()]); } /**