mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EA-44003 - SOE: PsiResolveHelperImpl.inferBySubtypingConstraint
This commit is contained in:
+18
-8
@@ -960,23 +960,33 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Key<Boolean> inferSubtyping = Key.create("infer.subtiping.marker");
|
||||
private static Pair<PsiType, ConstraintType> inferBySubtypingConstraint(PsiType patternType,
|
||||
ConstraintType constraintType,
|
||||
int depth,
|
||||
PsiClass paramClass, PsiClass argClass) {
|
||||
PsiClass paramClass,
|
||||
PsiClass argClass) {
|
||||
if (argClass instanceof PsiTypeParameter && paramClass instanceof PsiTypeParameter && PsiUtil.isLanguageLevel8OrHigher(argClass)) {
|
||||
final Boolean alreadyInferBySubtyping = paramClass.getCopyableUserData(inferSubtyping);
|
||||
if (alreadyInferBySubtyping != null) return null;
|
||||
final PsiClassType[] argExtendsListTypes = argClass.getExtendsListTypes();
|
||||
final PsiClassType[] paramExtendsListTypes = paramClass.getExtendsListTypes();
|
||||
if (argExtendsListTypes.length == paramExtendsListTypes.length) {
|
||||
for (int i = 0; i < argExtendsListTypes.length; i++) {
|
||||
PsiClassType argBoundType = argExtendsListTypes[i];
|
||||
PsiClassType paramBoundType = paramExtendsListTypes[i];
|
||||
final Pair<PsiType, ConstraintType> constraint =
|
||||
getSubstitutionForTypeParameterInner(paramBoundType, argBoundType, patternType, constraintType, depth);
|
||||
if (constraint != null) {
|
||||
return constraint;
|
||||
try {
|
||||
paramClass.putCopyableUserData(inferSubtyping, true);
|
||||
for (int i = 0; i < argExtendsListTypes.length; i++) {
|
||||
PsiClassType argBoundType = argExtendsListTypes[i];
|
||||
PsiClassType paramBoundType = paramExtendsListTypes[i];
|
||||
final Pair<PsiType, ConstraintType> constraint =
|
||||
getSubstitutionForTypeParameterInner(paramBoundType, argBoundType, patternType, constraintType, depth);
|
||||
if (constraint != null) {
|
||||
return constraint;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
paramClass.putCopyableUserData(inferSubtyping, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import java.util.Map;
|
||||
|
||||
public class SOE {
|
||||
|
||||
public static <K extends M, M extends Map<K,M>> M foo() {return null;}
|
||||
public static <K1 extends M1, M1 extends Map<K1,M1>> Map<K1, M1> foo1() {return foo();}
|
||||
}
|
||||
+4
@@ -64,6 +64,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSOEDuringInferenceFromParamBounds() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user