ensure fresh variables for the same context don't conflict by names (IDEA-196642)

This commit is contained in:
Anna.Kozlova
2018-08-06 19:32:06 +02:00
parent 83ed9bf603
commit 779291d906
3 changed files with 18 additions and 3 deletions

View File

@@ -1027,6 +1027,7 @@ public class InferenceSession {
protected void resolveBounds(final Collection<InferenceVariable> inferenceVariables,
@NotNull PsiSubstitutor substitutor) {
final UniqueNameGenerator uniqueNameGenerator = new UniqueNameGenerator();
final Collection<InferenceVariable> allVars = new ArrayList<>(inferenceVariables);
while (!allVars.isEmpty()) {
final List<InferenceVariable> 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<InferenceVariable> vars) {
private boolean initFreshVariables(PsiSubstitutor substitutor, List<InferenceVariable> 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();

View File

@@ -0,0 +1,14 @@
class MyTest {
static class Foo<A> {}
static <B> void bar(Foo<? super B> f1, Foo<? super B> f2) { }
{
bar<error descr="'bar(MyTest.Foo<? super B>, MyTest.Foo<? super B>)' in 'MyTest' cannot be applied to '(MyTest.Foo<T>, MyTest.Foo<T>)'">(m(), m())</error>;
}
static <T extends Comparable<T>> Foo<T> m() {
return null;
}
}

View File

@@ -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(); }