red code is green: impossible to have 2 signatures with same signature and different primitive return types (IDEA-102866)

(cherry picked from commit c4093d0e8a1021f80fafb3c6b1fc35388da46ac6)
This commit is contained in:
anna
2013-03-15 21:38:19 +01:00
parent 7f1f607d98
commit 8ed5a8175f
3 changed files with 25 additions and 4 deletions
@@ -1061,10 +1061,13 @@ public class HighlightMethodUtil {
if (otherSuperReturnType == null || currentType == null || otherSuperReturnType.equals(currentType)) continue;
if (PsiUtil.isLanguageLevel5OrHigher(currentMethod)) {
if (otherSuperReturnType.isAssignableFrom(currentType)) continue;
if (currentType.isAssignableFrom(otherSuperReturnType)) {
returnTypeSubstitutable = otherSuperSignature;
continue;
//http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.4.8 Example 8.1.5-3
if (!(otherSuperReturnType instanceof PsiPrimitiveType || currentType instanceof PsiPrimitiveType)) {
if (otherSuperReturnType.isAssignableFrom(currentType)) continue;
if (currentType.isAssignableFrom(otherSuperReturnType)) {
returnTypeSubstitutable = otherSuperSignature;
continue;
}
}
}
return createIncompatibleReturnTypeMessage(currentMethod, currentMethod, otherSuperMethod, false, otherSuperReturnType,
@@ -0,0 +1,17 @@
interface X4 { Integer m(); }
interface Y4 { Number m(); }
interface Z4 extends X4, Y4 {}
interface X1 { long m(); }
interface Y1 { Number m(); }
<error descr="'m()' in 'Y1' clashes with 'm()' in 'X1'; methods have unrelated return types">interface Z1 extends X1, Y1</error> {}
interface X2 { long m(); }
interface Y2 { int m(); }
<error descr="'m()' in 'X2' clashes with 'm()' in 'Y2'; methods have unrelated return types">interface Z2 extends X2, Y2</error> {}
interface X3 { String m(); }
interface Y3 { Integer m(); }
<error descr="'m()' in 'Y3' clashes with 'm()' in 'X3'; methods have unrelated return types">interface Z3 extends X3, Y3</error> {}
@@ -58,4 +58,5 @@ public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase {
}
public void testJavacQuirks() throws Exception { setLanguageLevel(LanguageLevel.JDK_1_6); doTest(true, false); }
public void testMethodReturnTypeSubstitutability() throws Exception { setLanguageLevel(LanguageLevel.JDK_1_6); doTest(true, false); }
}