don't loose type parameter bounds during super substitution (IDEA-175471)

This commit is contained in:
Anna.Kozlova
2017-07-07 12:46:41 +02:00
parent 13a25ce448
commit 4e8a0d2dd8
6 changed files with 31 additions and 3 deletions

View File

@@ -265,8 +265,8 @@ public class GenericsHighlightUtil {
}
final PsiClassType[] bounds = classParameter.getSuperTypes();
for (PsiClassType type1 : bounds) {
PsiType bound = substitutor.substitute(type1);
for (PsiType bound : bounds) {
bound = substitutor.substitute(bound);
if (!bound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) && GenericsUtil.checkNotInBounds(type, bound, referenceParameterList)) {
PsiClass boundClass = bound instanceof PsiClassType ? ((PsiClassType)bound).resolve() : null;

View File

@@ -129,7 +129,12 @@ public class JavaClassSupersImpl extends JavaClassSupers {
Map<PsiTypeParameter, PsiType> innerMap = inner.getSubstitutionMap();
for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable(onClass)) {
if (outerMap.containsKey(parameter) || innerMap.containsKey(parameter)) {
answer = answer.put(parameter, outer.substitute(inner.substitute(parameter)));
PsiType innerType = inner.substitute(parameter);
PsiClass paramCandidate = PsiCapturedWildcardType.isCapture() ? PsiUtil.resolveClassInClassTypeOnly(innerType) : null;
PsiType targetType = paramCandidate instanceof PsiTypeParameter && paramCandidate != parameter
? outer.substituteWithBoundsPromotion((PsiTypeParameter)paramCandidate)
: outer.substitute(innerType);
answer = answer.put(parameter, targetType);
}
}
return answer;

View File

@@ -0,0 +1,12 @@
class P<T, Self extends P<T, Self>> { }
class MM<T, H extends P<T, H>> {
H last;
void m(final Function<P<T, ?>, P<T, ?>> function) {
generate(last, function);
}
public static <E> void generate(E first, Function<? super E, ? extends E> generator) { }
}
interface Function<Param, Result> {}

View File

@@ -0,0 +1,9 @@
import java.io.Serializable;
import java.util.List;
interface Child<T extends Serializable> extends List<T> {
default void m(List<Child<?>> l) {
List<? extends List<? extends Serializable>> ll = l;
}
}

View File

@@ -425,4 +425,5 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testUncheckedWarningWhenCastingFromCapturedWildcard() { doTest8Incompatibility(true); }
public void testEnclosingRefInTopLevelClassExtendingInnerWhichExtendsItsOuter() { doTest8Incompatibility(true); }
public void testGenericThrowTypes() { doTest5(false); }
public void testRecursiveParamBoundsWhenSuperSubstitution() { doTest6(false); }
}

View File

@@ -1032,4 +1032,5 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
}
public void testBridgeMethodOverriding() { doTest(); }
public void testNestedWildcardsWithImplicitBounds() { doTest(); }
}