lambda: get info for return types from type arguments

This commit is contained in:
Anna Kozlova
2012-09-03 12:42:35 +04:00
parent e15a1b0e04
commit 8797c54ace
4 changed files with 26 additions and 1 deletions
@@ -289,6 +289,11 @@ public class LambdaUtil {
public static boolean isFreeFromTypeInferenceArgs(final PsiParameter[] methodParameters,
final PsiLambdaExpression lambdaExpression,
final PsiExpression expression) {
if (expression instanceof PsiCallExpression && ((PsiCallExpression)expression).getTypeArguments().length > 0) return true;
if (expression instanceof PsiNewExpression) {
final PsiJavaCodeReferenceElement classReference = ((PsiNewExpression)expression).getClassOrAnonymousClassReference();
if (classReference != null && classReference.getTypeParameters().length > 0) return true;
}
final PsiParameter[] lambdaParams = lambdaExpression.getParameterList().getParameters();
if (lambdaParams.length != methodParameters.length) return false;
final boolean [] independent = new boolean[]{true};
@@ -629,7 +629,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
}
final Pair<PsiType, ConstraintType> returnExprConstraint =
getSubstitutionForTypeParameterConstraint(typeParam, returnType, exprType, false, PsiUtil.getLanguageLevel(method));
getSubstitutionForTypeParameterConstraint(typeParam, returnType, exprType, true, PsiUtil.getLanguageLevel(method));
if (returnExprConstraint != null) {
if (returnExprConstraint == FAILED_INFERENCE) return returnExprConstraint;
if (constraint != null) {
@@ -0,0 +1,16 @@
import java.util.*;
public class BugReportLambdaSquiggles<T> {
private T t;
public <V> List<V> flatMap(Mapper<T, List<V>> mapper) {
return mapper.map(t);
}
static void bar( BugReportLambdaSquiggles<Integer> x) {
x.flatMap(t1 -> new ArrayList<String>(t1));
}
interface Mapper<T, U> {
U map(T t);
}
}
@@ -68,6 +68,10 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testInferenceOnMethodCallSite() throws Exception {
doTest();
}
public void testInferFromTypeArgs() throws Exception {
doTest();
}
public void testAmbiguity1() throws Exception {
doTest();