incompatible return types in hierarchy fixed (IDEA-173809)

take parameter bounds into account
This commit is contained in:
Anna Kozlova
2017-06-05 19:40:36 +03:00
parent fbd082f075
commit a5501a81c0
3 changed files with 15 additions and 1 deletions

View File

@@ -195,7 +195,9 @@ public class HighlightMethodUtil {
if (returnType.equals(substitutedSuperReturnType)) return null;
if (!(returnType instanceof PsiPrimitiveType) && substitutedSuperReturnType.getDeepComponentType() instanceof PsiClassType) {
if (isJdk15 && TypeConversionUtil.isAssignable(substitutedSuperReturnType, returnType)) {
if (isJdk15 && LambdaUtil.performWithSubstitutedParameterBounds(methodSignature.getTypeParameters(),
methodSignature.getSubstitutor(),
() -> TypeConversionUtil.isAssignable(substitutedSuperReturnType, returnType))) {
return null;
}
}

View File

@@ -0,0 +1,10 @@
class ListA<Ta> {
public <R extends Ta> Ta foo() { throw new Error(); }
}
class ListB<Tb> extends ListA<Tb> {
public <Rb extends Tb> Rb foo() { throw new Error(); }
}
class ListC<Tc> extends ListB<Tc> {
}

View File

@@ -180,6 +180,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testInaccessibleThroughWildcard() { doTest7Incompatibility(false);}
public void testInconvertibleTypes() { doTest5(false); }
public void testIncompatibleReturnType() { doTest5(false); }
public void testContinueInferenceAfterFirstRawResult() { doTest5(false); }
public void testDoNotAcceptLowerBoundIfRaw() { doTest5(false); }
public void testStaticOverride() { doTest5(false); }
@@ -342,6 +343,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA71582() { doTest5(false); }
public void testIDEA65377() { doTest5(false); }
public void testIDEA113526() { doTest5(true); }
public void testIncompatibleReturnTypeBounds() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA116493() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA117827() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA118037() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }