inference: allow capture during intersection type construction (IDEA-173900)

This commit is contained in:
Anna Kozlova
2017-09-13 15:33:56 +03:00
parent 06dc99b636
commit b9e2c4130d
4 changed files with 28 additions and 3 deletions
@@ -16,7 +16,6 @@
package com.intellij.psi;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.RecursionGuard;
import com.intellij.openapi.util.RecursionManager;
import com.intellij.psi.search.GlobalSearchScope;
@@ -83,13 +82,17 @@ public class PsiCapturedWildcardType extends PsiType.Stub {
glb = substitutedBoundType;
}
else {
glb = GenericsUtil.getGreatestLowerBound(glb, substitutedBoundType);
glb = getGreatestLowerBound(glb, substitutedBoundType, wildcardType);
}
}
return glb;
}
private static PsiType getGreatestLowerBound(PsiType glb, PsiType bound, Object guardObject) {
return guard.doPreventingRecursion(guardObject, true, () -> GenericsUtil.getGreatestLowerBound(glb, bound));
}
@Override
public boolean equals(Object o) {
if (!(o instanceof PsiCapturedWildcardType)) {
@@ -60,7 +60,7 @@ public class PsiIntersectionType extends PsiType.Stub {
@NotNull
private static PsiType[] flattenAndRemoveDuplicates(@NotNull PsiType[] conjuncts) {
try {
final Set<PsiType> flattenConjuncts = PsiCapturedWildcardType.guard.doPreventingRecursion(conjuncts, true, () -> flatten(conjuncts, ContainerUtil.newLinkedHashSet()));
final Set<PsiType> flattenConjuncts = flatten(conjuncts, ContainerUtil.newLinkedHashSet());
if (flattenConjuncts == null) {
return conjuncts;
}
@@ -0,0 +1,21 @@
abstract class Bug {
void m1(){
D<?> jobHandler = m();
}
abstract <J extends C<? extends B>> J m();
}
interface B {
}
abstract class C<T extends B> {
}
abstract class D<T extends E> extends C<T> {
}
abstract class E<T extends String> implements B { }
@@ -116,6 +116,7 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
public void testIDEA149774() { doTest(); }
public void testDisjunctionTypes() { doTest(); }
public void testValidIntersectionTypeWithCapturedBounds() { doTest(); }
public void testValidIntersectionTypeWithCapturedBounds1() { doTest(); }
public void testPushErasedStateToArguments() { doTest(); }
public void testStopAtStandaloneConditional() { doTest(); }
public void testTransitiveInferenceVariableDependencies() { doTest(); }