mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inference: incorporation with capture and fresh variables (IDEA-145566)
This commit is contained in:
+11
-3
@@ -21,6 +21,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.ConstraintFormula;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.StrictSubtypingConstraint;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.TypeEqualityConstraint;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.Processor;
|
||||
|
||||
import java.util.*;
|
||||
@@ -110,7 +111,7 @@ public class InferenceIncorporationPhase {
|
||||
if (aType instanceof PsiWildcardType) {
|
||||
|
||||
for (PsiType eqBound : eqBounds) {
|
||||
if (mySession.getInferenceVariable(eqBound) == null) return false;
|
||||
if (!isInferenceVariableOrFreshTypeParameter(eqBound)) return false;
|
||||
}
|
||||
|
||||
final PsiClassType[] paramBounds = inferenceVariable.getParameter().getExtendsListTypes();
|
||||
@@ -134,7 +135,7 @@ public class InferenceIncorporationPhase {
|
||||
}
|
||||
|
||||
for (PsiType lowerBound : lowerBounds) {
|
||||
if (mySession.getInferenceVariable(lowerBound) == null) return false;
|
||||
if (isInferenceVariableOrFreshTypeParameter(lowerBound)) return false;
|
||||
}
|
||||
|
||||
} else if (((PsiWildcardType)aType).isExtends()) {
|
||||
@@ -153,7 +154,7 @@ public class InferenceIncorporationPhase {
|
||||
}
|
||||
|
||||
for (PsiType lowerBound : lowerBounds) {
|
||||
if (mySession.getInferenceVariable(lowerBound) == null) return false;
|
||||
if (isInferenceVariableOrFreshTypeParameter(lowerBound)) return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -180,6 +181,13 @@ public class InferenceIncorporationPhase {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Boolean isInferenceVariableOrFreshTypeParameter(PsiType eqBound) {
|
||||
final PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(eqBound);
|
||||
if (psiClass instanceof InferenceVariable ||
|
||||
psiClass instanceof PsiTypeParameter && InferenceSession.isFreshVariable((PsiTypeParameter)psiClass)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean isFullyIncorporated() {
|
||||
boolean needFurtherIncorporation = false;
|
||||
for (InferenceVariable inferenceVariable : mySession.getInferenceVariables()) {
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
class Test {
|
||||
void foo(Function<String, List<String>> f) {
|
||||
DS<List<String>> ds = flatMap(f);
|
||||
}
|
||||
|
||||
|
||||
public <R> Operator<R, ?> flatMap(Function<String, R> flatMapper) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class Operator<OUT, O extends Operator<OUT, O>> extends DS<OUT> {}
|
||||
class DS<OUT> {}
|
||||
+4
@@ -303,6 +303,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testReturnConstraintsWithCaptureIncorporationOfFreshVariables() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user