[java-dfa] Return PSI-type for ExactSubclass

We don't specify that getPsiType() returns exact type, it may return a supertype. On the other hand, some clients assume that it returns exact type when isExact is true, so this may cause surprises for them

GitOrigin-RevId: 70165d6dadea07995dd0f1d6a456814b3970bad6
This commit is contained in:
Tagir Valeev
2024-07-11 10:58:22 +02:00
committed by intellij-monorepo-bot
parent 072efa77e1
commit 78a77d064c
2 changed files with 7 additions and 1 deletions

View File

@@ -556,7 +556,7 @@ public final class CustomMethodHandlers {
private static @NotNull DfType objectGetClass(DfaCallArguments arguments, DfaMemoryState state, DfaValueFactory factory, PsiMethod method) {
DfaValue qualifier = arguments.myQualifier;
TypeConstraint fact = TypeConstraint.fromDfType(state.getDfType(qualifier));
if (fact instanceof TypeConstraint.Exact) {
if (fact instanceof TypeConstraint.Exact && !(fact instanceof TypeConstraints.ExactSubclass)) {
PsiType qualifierType = fact.getPsiType(factory.getProject());
PsiType classType = method.getReturnType();
if (classType != null && qualifierType != null) {

View File

@@ -484,6 +484,12 @@ public final class TypeConstraints {
return new ExactSubclass(myId, ContainerUtil.map2Array(mySupers, Exact.class, ex -> ex.convert(factory)));
}
@Override
public @Nullable PsiType getPsiType(Project project) {
PsiType[] types = StreamEx.of(mySupers).map(st -> st.getPsiType(project)).distinct().toArray(PsiType.EMPTY_ARRAY);
return types.length == 0 ? null : PsiIntersectionType.createIntersection(types);
}
@Override
public boolean isFinal() {
return true;