new inference: forget nested states when expressions were processed second time (IDEA-153897)

This commit is contained in:
Anna.Kozlova
2016-03-30 21:02:16 +02:00
parent 77b5d5469c
commit e6426783b4
3 changed files with 45 additions and 0 deletions
@@ -125,6 +125,15 @@ public class InferenceSessionContainer {
final InferenceSessionContainer copy = new InferenceSessionContainer() {
@Override
public PsiSubstitutor findNestedSubstitutor(PsiElement arg, @Nullable PsiSubstitutor defaultSession) {
//for the case foo(bar(a -> m())): top level inference won't touch lambda "a -> m()"
//for the case foo(a -> bar(b -> m())): top level inference would go till nested lambda "b -> m()" and the state from top level could be found here by "bar(b -> m())"
//but proceeding with additional constraints from saved point would produce new expression constraints with different inference variables (could be found in myNestedSessions)
//which won't be found in the system if we won't reject stored sessions in such cases
final PsiSubstitutor substitutor = super.findNestedSubstitutor(arg, null);
if (substitutor != null) {
return substitutor;
}
final InitialInferenceState state = nestedStates.get(PsiTreeUtil.getParentOfType(arg, PsiCall.class));
if (state != null) {
return state.getInferenceSubstitutor();
@@ -0,0 +1,32 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static java.util.stream.IntStream.range;
class Test {
public static void main(String[] args) {
final int[] ints = new int[9];
final Stream<Object> empty = Stream.empty();
final IntStream range = range(0, 9);
empty.flatMap(e -> range.mapToObj(i -> range.mapToObj(j -> ints)));
final Stream<int[]> stream = empty.flatMap(e -> range(9, 0).mapToObj(i -> range.mapToObj(j -> ints))).flatMap(s -> s);
System.out.println(stream);
}
}
@@ -292,6 +292,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testDeepChainOfNestedLambdasOverCachedTopLevel() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}