private static boolean isCompatibleType(@NotNull PsiVariable var, @NotNull PsiType type, @Nullable String mostAbstractAllowedType) {
    if (EquivalenceChecker.getCanonicalPsiEquivalence().typesAreEquivalent(var.getType(), type)) return true;
    if (mostAbstractAllowedType == null) return false;
    PsiType[] superTypes = type.getSuperTypes();
    return ContainerUtil.exists(superTypes, superType -> InheritanceUtil.isInheritor(superType, mostAbstractAllowedType) &&
                                                           isCompatibleType(var, superType, mostAbstractAllowedType));
  }
private static boolean isCompatibleType(@NotNull PsiVariable var, @NotNull PsiType type, @Nullable String mostAbstractAllowedType)