old inference: choose child type between types in subtypes constraint (IDEA-118536)

This commit is contained in:
Anna Kozlova
2014-05-30 23:31:13 +04:00
parent d311a4ed09
commit b7ab465ad9
3 changed files with 17 additions and 1 deletions
@@ -286,7 +286,8 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
Pair<PsiType, ConstraintType> otherConstraint =
inferMethodTypeParameterFromParent(typeParameter, partialSubstitutor, parent, policy);
if (otherConstraint != null) {
if (otherConstraint.getSecond() == ConstraintType.EQUALS || otherConstraint.getSecond() == ConstraintType.SUPERTYPE) {
if (otherConstraint.getSecond() == ConstraintType.EQUALS || otherConstraint.getSecond() == ConstraintType.SUPERTYPE ||
compareSubtypes(constraint.getFirst(), otherConstraint.getFirst())) {
constraint = otherConstraint;
}
}
@@ -307,6 +308,10 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
return partialSubstitutor;
}
private static boolean compareSubtypes(final PsiType type, final PsiType parentType) {
return type != null && parentType != null && TypeConversionUtil.isAssignable(type, parentType);
}
@Override
@NotNull
public PsiSubstitutor inferTypeArguments(@NotNull PsiTypeParameter[] typeParameters,
@@ -0,0 +1,10 @@
import java.util.Comparator;
class MyTest {
void foo(final Ordering<Comparable> natural){
compound(natural);
}
<U extends String> Ordering<U> compound(Comparator<? super U> secondaryComparator) { return null; }
}
abstract class Ordering <T> implements Comparator<T> {}
@@ -353,6 +353,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA123509() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA125031() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA24479() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA118536() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testJavaUtilCollections_NoVerify() throws Exception {
PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));