mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
intersection types for PsiTypeVisitor; do not convert intersection type to class type even when no actual substitution is needed
(cherry picked from commit 4670ddf57981f596122082365e43587990c3a53e)
This commit is contained in:
@@ -137,7 +137,7 @@ public class PsiIntersectionType extends PsiType {
|
||||
|
||||
@Override
|
||||
public <A> A accept(@NotNull PsiTypeVisitor<A> visitor) {
|
||||
return myConjuncts[0].accept(visitor);
|
||||
return visitor.visitIntersectionType(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -63,6 +63,12 @@ public class PsiTypeVisitor<A> {
|
||||
return visitType(disjunctionType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public A visitIntersectionType(PsiIntersectionType intersectionType) {
|
||||
PsiType type = intersectionType.getConjuncts()[0];
|
||||
return type.accept(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public A visitDiamondType(PsiDiamondType diamondType) {
|
||||
return visitType(diamondType);
|
||||
|
||||
@@ -238,6 +238,18 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
|
||||
@Override
|
||||
public abstract PsiType visitClassType(PsiClassType classType);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiType visitIntersectionType(PsiIntersectionType intersectionType) {
|
||||
final List<PsiType> substituted = ContainerUtil.map(intersectionType.getConjuncts(), new Function<PsiType, PsiType>() {
|
||||
@Override
|
||||
public PsiType fun(PsiType psiType) {
|
||||
return psiType.accept(SubstitutionVisitorBase.this);
|
||||
}
|
||||
});
|
||||
return PsiIntersectionType.createIntersection(substituted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType visitDisjunctionType(PsiDisjunctionType disjunctionType) {
|
||||
final List<PsiType> substituted = ContainerUtil.map(disjunctionType.getDisjunctions(), new Function<PsiType, PsiType>() {
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
class Test {
|
||||
|
||||
interface A {}
|
||||
interface B {}
|
||||
static interface C extends A, B {}
|
||||
static interface D extends A, B {}
|
||||
|
||||
interface I<T, V> {
|
||||
V fun(T arg);
|
||||
}
|
||||
<Z> Z m(Z z) { return z; }
|
||||
|
||||
void test(C c, D d) {
|
||||
choose(c, d, x -> x);
|
||||
choose(c, d, this::m);
|
||||
}
|
||||
|
||||
<T> void choose(T t1, T t2, I<T, T> t3) {}
|
||||
}
|
||||
+4
@@ -70,6 +70,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIntersectionTypesDuringInference() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user