check to prevent contradicted intersection type (IDEA-67600)

This commit is contained in:
Anna Kozlova
2014-06-09 17:03:12 +04:00
parent 046b90c352
commit 27f10a6c30
3 changed files with 31 additions and 1 deletions
@@ -371,7 +371,12 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
!TypeConversionUtil.erasure(substitutedBoundType).isAssignableFrom(TypeConversionUtil.erasure(originalBound)) &&
!TypeConversionUtil.erasure(substitutedBoundType).isAssignableFrom(originalBound)) { //erasure is essential to avoid infinite recursion
if (wildcardType.isExtends()) {
final PsiType glb = GenericsUtil.getGreatestLowerBound(wildcardType.getBound(), substitutedBoundType);
final PsiType bound = wildcardType.getBound();
if (bound instanceof PsiArrayType && substitutedBoundType instanceof PsiArrayType &&
!bound.isAssignableFrom(substitutedBoundType) && !substitutedBoundType.isAssignableFrom(bound)) {
continue;
}
final PsiType glb = GenericsUtil.getGreatestLowerBound(bound, substitutedBoundType);
if (glb != null) {
substituted = PsiWildcardType.createExtends(manager, glb);
}
@@ -0,0 +1,24 @@
abstract class A<T, S extends T>
{
abstract S bar();
void foo(A<Runnable[], ? extends Cloneable[]> a){
<error descr="Incompatible types. Found: 'java.lang.Cloneable[]', required: 'java.lang.Runnable[]'">Runnable[] x = a.bar();</error>
}
}
abstract class AB<T, S extends T>
{
abstract S bar();
void foo(AB<Runnable, ? extends Cloneable> a){
Runnable x = a.bar();
}
}
abstract class AC<T, S>
{
abstract S bar();
void foo(AC<Runnable[], ? extends Cloneable[]> a){
<error descr="Incompatible types. Found: 'java.lang.Cloneable[]', required: 'java.lang.Runnable[]'">Runnable[] x = a.bar();</error>
}
}
@@ -367,6 +367,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA125800() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA125816() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA57338() { doTest(LanguageLevel.JDK_1_6, JavaSdkVersion.JDK_1_6, false); }
public void testIDEA67600() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
//jdk should propagate LL 1.4 but actually it provides LL 1.7?!
public void testCastObjectToIntJdk14() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_4, false); }