diff --git a/java/java-psi-api/src/com/intellij/psi/util/TypesDistinctProver.java b/java/java-psi-api/src/com/intellij/psi/util/TypesDistinctProver.java index e147b4060848..9ff34755e90f 100644 --- a/java/java-psi-api/src/com/intellij/psi/util/TypesDistinctProver.java +++ b/java/java-psi-api/src/com/intellij/psi/util/TypesDistinctProver.java @@ -38,12 +38,12 @@ public class TypesDistinctProver { protected static boolean provablyDistinct(PsiType type1, PsiType type2, int level) { if (type1 instanceof PsiWildcardType) { if (type2 instanceof PsiWildcardType) { - return provablyDistinct((PsiWildcardType)type1, (PsiWildcardType)type2, true); + return provablyDistinct((PsiWildcardType)type1, (PsiWildcardType)type2, true, level); } if (level > 1) return true; if (type2 instanceof PsiCapturedWildcardType) { - return provablyDistinct((PsiWildcardType)type1, ((PsiCapturedWildcardType)type2).getWildcard(), false); + return provablyDistinct((PsiWildcardType)type1, ((PsiCapturedWildcardType)type2).getWildcard(), false, level); } if (type2 instanceof PsiClassType) { @@ -150,7 +150,7 @@ public class TypesDistinctProver { return true; } - public static boolean provablyDistinct(PsiWildcardType type1, PsiWildcardType type2, boolean rejectInconsistentRaw) { + public static boolean provablyDistinct(PsiWildcardType type1, PsiWildcardType type2, boolean rejectInconsistentRaw, int level) { if (type1.isSuper() && type2.isSuper()) return false; if (type1.isExtends() && type2.isExtends()) { final PsiType extendsBound1 = type1.getExtendsBound(); @@ -168,7 +168,8 @@ public class TypesDistinctProver { } return provablyDistinct(extendsBound1, extendsBound2, 1); } - if (type2.isExtends()) return provablyDistinct(type2, type1, rejectInconsistentRaw); + if (type2.isExtends()) return provablyDistinct(type2, type1, rejectInconsistentRaw, level); + if (type1.isExtends() && !type2.isBounded() && level > 1) return PsiUtil.resolveClassInType(type1.getExtendsBound()) instanceof PsiTypeParameter; if (type1.isExtends() && type2.isSuper()) { final PsiType extendsBound = type1.getExtendsBound(); final PsiType superBound = type2.getSuperBound(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA120563.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA120563.java new file mode 100644 index 000000000000..fb60ea55a5d5 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA120563.java @@ -0,0 +1,33 @@ + +import java.util.Set; + +public class WrongGenerics { + + @SuppressWarnings("unchecked") + Set> foo(Set> foo) { + return (Set>)foo; + } + + @SuppressWarnings("unchecked") + Set> bar(Set> foo) { + return (Set>) foo; + } + + @SuppressWarnings("unchecked") + Foo bothSucceed(Foo foo) { + return (Foo) foo; + } + + @SuppressWarnings("unchecked") + Foo> bothFail(Foo> foo) { + return (Foo>) foo; + } + + @SuppressWarnings("unchecked") + Set> onlyIntelliJSucceeds(Set> foo) { + return (Set>) foo; + } +} + +class Foo { +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index 2ed84c6ab14d..9b8861a5a01c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -337,6 +337,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testIDEA119546() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); } public void testIDEA118527() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); } public void testIDEA120153() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); } + public void testIDEA120563() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); } public void testSuperWildcardWithBoundPromotion() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);}