mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
lambda: stop inference from lambda if return type retrieval leads to second lambda inference; do not cache types during this calculation
This commit is contained in:
@@ -88,9 +88,10 @@ public class JavaResolveCache {
|
||||
public <T extends PsiExpression> PsiType getType(@NotNull T expr, @NotNull Function<T, PsiType> f) {
|
||||
PsiType type = getCachedType(expr);
|
||||
if (type == null) {
|
||||
final RecursionGuard.StackStamp stackStamp = PsiDiamondType.ourDiamondGuard.markStack();
|
||||
final RecursionGuard.StackStamp dStackStamp = PsiDiamondType.ourDiamondGuard.markStack();
|
||||
final RecursionGuard.StackStamp gStackStamp = PsiResolveHelper.ourGraphGuard.markStack();
|
||||
type = f.fun(expr);
|
||||
if (!stackStamp.mayCacheNow()) {
|
||||
if (!dStackStamp.mayCacheNow() || !gStackStamp.mayCacheNow()) {
|
||||
return type;
|
||||
}
|
||||
if (type == null) type = TypeConversionUtil.NULL_TYPE;
|
||||
|
||||
@@ -739,7 +739,12 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
continue;
|
||||
}
|
||||
if (expression instanceof PsiReferenceExpression && ((PsiReferenceExpression)expression).resolve() == null) continue;
|
||||
PsiType exprType = expression.getType();
|
||||
PsiType exprType = ourGraphGuard.doPreventingRecursion(expression, true, new Computable<PsiType>() {
|
||||
@Override
|
||||
public PsiType compute() {
|
||||
return expression.getType();
|
||||
}
|
||||
});
|
||||
if (exprType instanceof PsiLambdaParameterType) {
|
||||
final PsiParameter parameter = ((PsiLambdaParameterType)exprType).getParameter();
|
||||
final int parameterIndex = lambdaExpression.getParameterList().getParameterIndex(parameter);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import java.util.*;
|
||||
public class Main1 {
|
||||
|
||||
interface I<T> {
|
||||
List<T> f();
|
||||
}
|
||||
|
||||
static class Test {
|
||||
<Z> void m(I<Z> i, I<Z> ii) {
|
||||
}
|
||||
|
||||
<Z> void m(I<Z> s) {
|
||||
}
|
||||
|
||||
{
|
||||
m(() -> emptyList(), () -> new ArrayList<String>());
|
||||
m(() -> new ArrayList<String>(), () -> emptyList());
|
||||
m((I<String>) () -> emptyList(), () -> new ArrayList<String>());
|
||||
m(() -> Test.<String>emptyList(), () -> new ArrayList<String>());
|
||||
m(() -> emptyList());
|
||||
}
|
||||
|
||||
static <T> List<T> emptyList() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,6 +212,10 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInferenceFromSecondLambda() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user