From d3f31f402f1b064c05d794213291e807d69131d1 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 8 May 2013 14:19:00 +0200 Subject: [PATCH] type parameter cannot be inherited with different arguments as well as any other class (IDEA-57324) --- .../impl/analysis/GenericsHighlightUtil.java | 5 ++-- .../src/com/intellij/psi/GenericsUtil.java | 2 ++ ...nheritedWithDifferentArgsInTypeParams.java | 24 +++++++++++++++++++ .../daemon/GenericsHighlightingTest.java | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/InheritedWithDifferentArgsInTypeParams.java diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java index 2c81cd071545..fd088bf30c18 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java @@ -415,7 +415,6 @@ public class GenericsHighlightUtil { } public static HighlightInfo checkInterfaceMultipleInheritance(PsiClass aClass) { - if (aClass instanceof PsiTypeParameter) return null; final PsiClassType[] types = aClass.getSuperTypes(); if (types.length < 2) return null; Map inheritedClasses = new HashMap(); @@ -442,8 +441,8 @@ public class GenericsHighlightUtil { if (inheritedSubstitutor != null) { final PsiTypeParameter[] typeParameters = superClass.getTypeParameters(); for (PsiTypeParameter typeParameter : typeParameters) { - PsiType type1 = inheritedSubstitutor.substitute(typeParameter); - PsiType type2 = superTypeSubstitutor.substitute(typeParameter); + PsiType type1 = GenericsUtil.eliminateWildcards(inheritedSubstitutor.substitute(typeParameter)); + PsiType type2 = GenericsUtil.eliminateWildcards(superTypeSubstitutor.substitute(typeParameter)); if (!Comparing.equal(type1, type2)) { String description = JavaErrorMessages.message("generics.cannot.be.inherited.with.different.type.arguments", diff --git a/java/java-psi-api/src/com/intellij/psi/GenericsUtil.java b/java/java-psi-api/src/com/intellij/psi/GenericsUtil.java index 06d40370d5b7..f2a623689c43 100644 --- a/java/java-psi-api/src/com/intellij/psi/GenericsUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/GenericsUtil.java @@ -385,6 +385,8 @@ public class GenericsUtil { final PsiType bound = ((PsiWildcardType)type).getBound(); return bound != null ? bound : ((PsiWildcardType)type).getExtendsBound();//object + } else if (type instanceof PsiCapturedWildcardType && !eliminateInTypeArguments) { + return eliminateWildcards(((PsiCapturedWildcardType)type).getWildcard(), eliminateInTypeArguments); } return type; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/InheritedWithDifferentArgsInTypeParams.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/InheritedWithDifferentArgsInTypeParams.java new file mode 100644 index 000000000000..2adff2f8f495 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/InheritedWithDifferentArgsInTypeParams.java @@ -0,0 +1,24 @@ +interface IA {} +interface IB extends IA {} + +class A { + <T extends IA & IB> void foo(){} +} + + + +interface IA1 {} +interface IB1 extends IA1 {} + +class A1 { + <T extends IA1 & IB1> void foo(){} +} + +interface IA2 {} +interface IB2 extends IA2 {} + +class A2 { + & IB2> void 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 6d92b93eda85..2c2a11ab74b5 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -235,6 +235,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testIDEA20573() throws Exception { doTest5(false);} public void testIDEA20244() throws Exception { doTest5(false);} public void testIDEA22005() throws Exception { doTest5(false);} + public void testInheritedWithDifferentArgsInTypeParams() throws Exception { doTest5(false);} public void testIDEA57877() throws Exception { doTest5(false);} public void testTypeParamsCyclicInference() throws Exception { doTest5(false);}