diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSuperMethodImplUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSuperMethodImplUtil.java index 61d7d54c077b..70f80b470158 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSuperMethodImplUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSuperMethodImplUtil.java @@ -215,15 +215,15 @@ public class PsiSuperMethodImplUtil { LOG.assertTrue(copy.getMethod().isValid()); map.put(signature, copy); } + else if (isSuperMethod(aClass, existing, hierarchicalMethodSignature)) { + mergeSupers(existing, hierarchicalMethodSignature); + } else if (isReturnTypeIsMoreSpecificThan(hierarchicalMethodSignature, existing) && isSuperMethod(aClass, hierarchicalMethodSignature, existing)) { HierarchicalMethodSignatureImpl newSuper = copy(hierarchicalMethodSignature); mergeSupers(newSuper, existing); LOG.assertTrue(newSuper.getMethod().isValid()); map.put(signature, newSuper); } - else if (isSuperMethod(aClass, existing, hierarchicalMethodSignature)) { - mergeSupers(existing, hierarchicalMethodSignature); - } // just drop an invalid method declaration there - to highlight accordingly else if (!result.containsKey(signature)) { LOG.assertTrue(hierarchicalMethodSignature.getMethod().isValid()); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideWithMoreSpecificReturn.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideWithMoreSpecificReturn.java new file mode 100644 index 000000000000..c2f68775cbfb --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideWithMoreSpecificReturn.java @@ -0,0 +1,15 @@ +import java.util.List; + +interface ExampleInterface { + public List exampleMethod(); +} + +class ExampleSuperClass { + public List exampleMethod() { + return null; + } +} + + +public class ExampleSubClass extends ExampleSuperClass implements ExampleInterface { +} 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 54f69672b856..efd46470ee23 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -206,6 +206,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testFlattenIntersectionType() throws Exception { doTest17Incompatibility(false); } public void testIDEA97276() throws Exception { doTest17Incompatibility(false); } public void testWildcardsBoundsIntersection() throws Exception { doTest17Incompatibility(false); } + public void testOverrideWithMoreSpecificReturn() throws Exception { doTest17Incompatibility(false); } public void testJavaUtilCollections_NoVerify() throws Exception { PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));