check if super wildcard is within its bounds (IDEA-95065)

This commit is contained in:
anna
2012-11-15 21:35:23 +01:00
parent 6f21decc3d
commit 2c3fd187d5
3 changed files with 23 additions and 2 deletions

View File

@@ -262,7 +262,7 @@ public class GenericsHighlightUtil {
final PsiClassType[] bounds = classParameter.getSuperTypes();
for (PsiClassType type1 : bounds) {
PsiType bound = substitutor.substitute(type1);
if (checkNotInBounds(type, bound)) {
if (!bound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) && checkNotInBounds(type, bound)) {
PsiClass boundClass = bound instanceof PsiClassType ? ((PsiClassType)bound).resolve() : null;
@NonNls final String messageKey = boundClass == null || referenceClass == null || referenceClass.isInterface() == boundClass.isInterface()
@@ -297,7 +297,7 @@ public class GenericsHighlightUtil {
return checkExtendsWildcardCaptureFailure((PsiWildcardType)type, bound);
}
else if (((PsiWildcardType)type).isSuper()) {
return checkNotAssignable(bound, ((PsiWildcardType)type).getSuperBound());
return checkNotAssignable(bound, ((PsiWildcardType)type).getSuperBound(), false);
}
}
else if (type instanceof PsiArrayType) {

View File

@@ -0,0 +1,20 @@
class TopGene<T> {
}
class MidRaw extends TopGene {
}
class BottomGene<T> extends MidRaw {
}
class GeneType<T extends TopGene<String>> {
}
class GeneUser {
public void success(GeneType<? extends BottomGene<String>> p) {
}
public void fail(GeneType<<error descr="Type parameter '? super BottomGene<String>' is not within its bound; should extend 'TopGene<java.lang.String>'">? super BottomGene<String></error>> p) {
}
}

View File

@@ -198,6 +198,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testRawOnParameterized() throws Exception { doTest(false); }
public void testFailedInferenceWithBoxing() throws Exception { doTest(false); }
public void testFixedFailedInferenceWithBoxing() throws Exception { doTest17Incompatibility(false); }
public void testSuperWildcardIsNotWithinItsBound() throws Exception { doTest17Incompatibility(false); }
public void testJavaUtilCollections_NoVerify() throws Exception {
PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));