TypeConstraint: fix deep hierarchy union (IDEA-CR-31134)

This commit is contained in:
Tagir Valeev
2018-03-30 13:30:43 +07:00
parent 1b7782b591
commit ea96b276bb
4 changed files with 45 additions and 1 deletions
@@ -197,7 +197,8 @@ public final class TypeConstraint {
private static Set<DfaPsiType> withSuper(Set<DfaPsiType> instanceofValues) {
return StreamEx.of(instanceofValues)
.flatMap(type -> StreamEx.of(type.getPsiType().getSuperTypes()).map(type.getFactory()::createDfaType).append(type))
.flatMap(type -> StreamEx.ofTree(type.getPsiType(), t -> StreamEx.of(t.getSuperTypes()))
.map(type.getFactory()::createDfaType))
.toSet();
}
@@ -0,0 +1,21 @@
import java.math.BigInteger;
import java.util.function.Function;
class Test {
interface Base {
void baseMethod();
}
interface A1 extends Base {}
interface A2 extends Base {}
interface B1 extends A1 {}
interface B2 extends A2 {}
interface C1 extends B1 {}
long test(Object obj) {
if (obj instanceof C1 || obj instanceof A2) {
obj.baseMe<caret>
}
return -1;
}
}
@@ -0,0 +1,21 @@
import java.math.BigInteger;
import java.util.function.Function;
class Test {
interface Base {
void baseMethod();
}
interface A1 extends Base {}
interface A2 extends Base {}
interface B1 extends A1 {}
interface B2 extends A2 {}
interface C1 extends B1 {}
long test(Object obj) {
if (obj instanceof C1 || obj instanceof A2) {
((Base) obj).baseMethod();
}
return -1;
}
}
@@ -63,6 +63,7 @@ class NormalCompletionDfaTest extends NormalCompletionTestCase {
void testInstanceOfAfterFunction() { doTest() }
void testInstanceOfDisjunction() { doTest() }
void testInstanceOfDisjunction2() { doTest() }
void testInstanceOfDisjunctionDeep() { doTest() }
void testComplexInstanceOfDfa() {
configureByTestName()
myFixture.assertPreferredCompletionItems 0, 'methodFromX', 'methodFromX2', 'methodFromY', 'methodFromY2'