From 779291d9060dca6be2dcd438adb8578d140de681 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Mon, 6 Aug 2018 19:32:06 +0200 Subject: [PATCH] ensure fresh variables for the same context don't conflict by names (IDEA-196642) --- .../resolve/graphInference/InferenceSession.java | 6 +++--- .../NameConflictBetweenFreshVariables.java | 14 ++++++++++++++ .../lambda/GraphInferenceHighlightingTest.java | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/NameConflictBetweenFreshVariables.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index df45da42c4f4..9f5d34a94984 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -1027,6 +1027,7 @@ public class InferenceSession { protected void resolveBounds(final Collection inferenceVariables, @NotNull PsiSubstitutor substitutor) { + final UniqueNameGenerator uniqueNameGenerator = new UniqueNameGenerator(); final Collection allVars = new ArrayList<>(inferenceVariables); while (!allVars.isEmpty()) { final List vars = InferenceVariablesOrder.resolveOrder(allVars, this); @@ -1054,7 +1055,7 @@ public class InferenceSession { } } - if (!initFreshVariables(substitutor, unresolved)) { + if (!initFreshVariables(substitutor, unresolved, uniqueNameGenerator)) { return; } @@ -1091,11 +1092,10 @@ public class InferenceSession { } } - private boolean initFreshVariables(PsiSubstitutor substitutor, List vars) { + private boolean initFreshVariables(PsiSubstitutor substitutor, List vars, UniqueNameGenerator nameGenerator) { final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(getManager().getProject()); PsiSubstitutor ySubstitutor = PsiSubstitutor.EMPTY; final PsiTypeParameter[] yVars = new PsiTypeParameter[vars.size()]; - UniqueNameGenerator nameGenerator = new UniqueNameGenerator(); for (int i = 0; i < vars.size(); i++) { InferenceVariable var = vars.get(i); final PsiTypeParameter parameter = var.getParameter(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/NameConflictBetweenFreshVariables.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/NameConflictBetweenFreshVariables.java new file mode 100644 index 000000000000..e56a1542c774 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/NameConflictBetweenFreshVariables.java @@ -0,0 +1,14 @@ +class MyTest { + + static class Foo {} + + static void bar(Foo f1, Foo f2) { } + + { + bar(m(), m()); + } + + static > Foo m() { + return null; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java index 0da9c12569a7..86f5322af0c3 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java @@ -166,6 +166,7 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase } } + public void testNameConflictBetweenFreshVariables() { doTest(); } public void testCreateFreshVariablesOnlyForWildcardPlacesDuringReturnTypeProcessing() { doTest(); } public void testCapturedConversionDuringDirectSuperCheck() { doTest(); } //public void _testResolutionOrderForVariableCycles() { doTest(); }