diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/TypeConstraint.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/TypeConstraint.java index 1c8b4393bc27..b4ac05397f1d 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/TypeConstraint.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/TypeConstraint.java @@ -197,7 +197,8 @@ public final class TypeConstraint { private static Set withSuper(Set 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(); } diff --git a/java/java-tests/testData/codeInsight/completion/normal/InstanceOfDisjunctionDeep.java b/java/java-tests/testData/codeInsight/completion/normal/InstanceOfDisjunctionDeep.java new file mode 100644 index 000000000000..ef670086ebfb --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/InstanceOfDisjunctionDeep.java @@ -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 + } + return -1; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normal/InstanceOfDisjunctionDeep_after.java b/java/java-tests/testData/codeInsight/completion/normal/InstanceOfDisjunctionDeep_after.java new file mode 100644 index 000000000000..4a6844fc627c --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/InstanceOfDisjunctionDeep_after.java @@ -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; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionDfaTest.groovy b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionDfaTest.groovy index d0a0758a77b1..abb30fdf0e48 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionDfaTest.groovy +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionDfaTest.groovy @@ -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'