new inference: lift type parameters; stop inference after false appears in bounds

This commit is contained in:
Anna Kozlova
2014-02-12 12:45:14 +01:00
parent ea25e613a0
commit b16df9509f
4 changed files with 12 additions and 7 deletions

View File

@@ -251,7 +251,7 @@ public class InferenceSession {
inferenceVariable.ignoreInstantiation();
}
if (!proceedWithAdditionalConstraints(additionalConstraints)) {
//return prepareSubstitution();
return prepareSubstitution();
}
}
}
@@ -636,9 +636,9 @@ public class InferenceSession {
for (List<InferenceVariable> variables : independentVars) {
for (InferenceVariable inferenceVariable : variables) {
if (inferenceVariable.getInstantiation() != PsiType.NULL) continue;
final PsiTypeParameter typeParameter = inferenceVariable.getParameter();
try {
if (inferenceVariable.getInstantiation() != PsiType.NULL) continue;
final List<PsiType> eqBounds = inferenceVariable.getBounds(InferenceBound.EQ);
final List<PsiType> lowerBounds = inferenceVariable.getBounds(InferenceBound.LOWER);
final List<PsiType> upperBounds = inferenceVariable.getBounds(InferenceBound.UPPER);
@@ -820,7 +820,10 @@ public class InferenceSession {
}
if (!dependsOnOutput) {
subset.add(constraint);
varsToResolve.addAll(inputVariables);
for (InferenceVariable variable : inputVariables) {
varsToResolve.addAll(variable.getDependencies(this));
varsToResolve.add(variable);
}
}
}
else {

View File

@@ -149,14 +149,16 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
}
LOG.assertTrue(referencedMethodReturnType != null, method);
session.initBounds(method.getTypeParameters());
session.initBounds(containingClass.getTypeParameters());
if (typeParameters.length == 0 && ((PsiMethod)resolve).getTypeParameters().length > 0) {
final PsiClass interfaceClass = classResolveResult.getElement();
LOG.assertTrue(interfaceClass != null);
if (PsiPolyExpressionUtil.mentionsTypeParameters(referencedMethodReturnType,
ContainerUtil.newHashSet(method.getTypeParameters()))) {
LOG.assertTrue(interfaceMethodReturnType != null);
constraints.add(new TypeCompatibilityConstraint(referencedMethodReturnType, interfaceMethodReturnType));
constraints.add(new TypeCompatibilityConstraint(referencedMethodReturnType, returnType));
return true;
}
}

View File

@@ -21,7 +21,7 @@ class NoInferenceResult {
m((String s1) -> s1.length());
m((String s1) -> s1);
m1(<error descr="Target type of a lambda conversion must be an interface">() -> { }</error>);
m1<error descr="'m1(T)' in 'NoInferenceResult' cannot be applied to '(<lambda expression>)'">(() -> { })</error>;
Foo<String> foo = new Foo<String>();
foo.map(v -> null);

View File

@@ -14,7 +14,7 @@ class NoLambda {
static <T> T id(T i2) {return i2;}
{
id(<error descr="Target type of a lambda conversion must be an interface">() -> {System.out.println("hi");}</error>);
id<error descr="'id(T)' in 'NoLambda' cannot be applied to '(<lambda expression>)'">(() -> {System.out.println("hi");})</error>;
NoLambda.<Runnable>id(() -> {System.out.println("hi");});
}
}