mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
calculate bound based on all type arguments (IDEA-57334)
This commit is contained in:
@@ -929,6 +929,8 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
return inferBySubtypingConstraint(patternType, constraintType, depth, paramClass, argClass);
|
||||
}
|
||||
|
||||
PsiType lowerBound = PsiType.NULL;
|
||||
PsiType upperBound = PsiType.NULL;
|
||||
Pair<PsiType,ConstraintType> wildcardCaptured = null;
|
||||
for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(paramClass)) {
|
||||
PsiType paramType = paramResult.getSubstitutor().substitute(typeParameter);
|
||||
@@ -950,13 +952,35 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
Pair<PsiType,ConstraintType> res = getSubstitutionForTypeParameterInner(paramType, argType, patternType, ConstraintType.EQUALS, depth + 1);
|
||||
|
||||
if (res != null) {
|
||||
PsiType type = res.getFirst();
|
||||
if (!(type instanceof PsiWildcardType)) return res;
|
||||
if (wildcardCaptured != null) return FAILED_INFERENCE;
|
||||
wildcardCaptured = res;
|
||||
final PsiType type = res.getFirst();
|
||||
switch (res.getSecond()) {
|
||||
case EQUALS:
|
||||
if (!(type instanceof PsiWildcardType)) return res;
|
||||
if (wildcardCaptured != null) return FAILED_INFERENCE;
|
||||
wildcardCaptured = res;
|
||||
break;
|
||||
case SUPERTYPE:
|
||||
wildcardCaptured = res;
|
||||
if (PsiType.NULL.equals(lowerBound)) {
|
||||
lowerBound = type;
|
||||
}
|
||||
else if (!lowerBound.equals(type)) {
|
||||
lowerBound = GenericsUtil.getLeastUpperBound(lowerBound, type, typeParameter.getManager());
|
||||
if (lowerBound == null) return FAILED_INFERENCE;
|
||||
}
|
||||
break;
|
||||
case SUBTYPE:
|
||||
wildcardCaptured = res;
|
||||
if (PsiType.NULL.equals(upperBound) || TypeConversionUtil.isAssignable(upperBound, type)) {
|
||||
upperBound = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lowerBound != PsiType.NULL) return new Pair<PsiType, ConstraintType>(lowerBound, ConstraintType.SUPERTYPE);
|
||||
if (upperBound != PsiType.NULL) return new Pair<PsiType, ConstraintType>(upperBound, ConstraintType.SUBTYPE);
|
||||
|
||||
return wildcardCaptured;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
abstract class A<T, S> {
|
||||
abstract <T> void foo(A<? extends T, ? extends T> x);
|
||||
void bar(A<? extends Throwable, ? extends Exception> x){
|
||||
foo(x);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class A0<T, S> {
|
||||
abstract <T> void foo(A0<? extends T, ? extends T> x);
|
||||
void bar(A0<? extends Exception, ? extends Throwable> x){
|
||||
foo(x);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class A1<T, S> {
|
||||
abstract <T> void foo(A1<? extends T, ? extends T> x);
|
||||
void bar(A1<? extends Throwable, Exception> x){
|
||||
foo(x);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class A10<T, S> {
|
||||
abstract <T> void foo(A10<? extends T, ? extends T> x);
|
||||
void bar(A10<Throwable, Exception> x){
|
||||
foo(x);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class A2<T, S> {
|
||||
abstract <T> void foo(A2<? super T, ? super T> x);
|
||||
void bar(A2<? super Exception, ? super Throwable> x){
|
||||
foo(x);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class A20<T, S> {
|
||||
abstract <T> void foo(A20<? super T, ? super T> x);
|
||||
void bar(A20<? super Throwable, ? super Exception> x){
|
||||
foo(x);
|
||||
}
|
||||
}
|
||||
@@ -291,6 +291,10 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testIDEA104160() {doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);}
|
||||
public void testSOEInLeastUpperClass() {doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);}
|
||||
|
||||
public void testIDEA57334() {
|
||||
doTest5(false);
|
||||
}
|
||||
|
||||
public void testJavaUtilCollections_NoVerify() throws Exception {
|
||||
PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));
|
||||
assertNotNull(collectionsClass);
|
||||
|
||||
Reference in New Issue
Block a user