DeclaredType implements InferredType { @Override public boolean isCompatibleWith(InferredType other) { if (alternativeTypeSymbols().isEmpty()) { return true; } return alternativeTypeSymbols().stream().anyMatch(typeSymbol -> InferredTypes.isTypeClassCompatibleWith(typeSymbol, other)); } DeclaredType(Symbol typeClass, List<DeclaredType> typeArgs);   DeclaredType(Symbol typeClass); @Override boolean canHaveMember(String memberName); @Override boolean declaresMember(String memberName); @Override boolean isIdentityComparableWith(InferredType other); @Override Optional<Symbol> resolveMember(String memberName); @Override Optional<Symbol> resolveDeclaredMember(String memberName); @Override boolean canBeOrExtend(String typeName); @Override boolean canOnlyBe(String typeName); @Override boolean isCompatibleWith(InferredType other); @Override boolean mustBeOrExtend(String typeName); @Override String toString(); String typeName(); Set<Symbol> alternativeTypeSymbols(); @Override boolean equals(Object o); @Override int hashCode(); static InferredType fromInferredType(InferredType inferredType);  }
@Test public void test_isCompatibleWith() { ClassSymbol x1 = lastClassSymbol( "class X1:", " def foo(): ..." ); ClassSymbol x2 = lastClassSymbol( "class X2:", " def bar(): ..." ); ((ClassSymbolImpl) x2).addSuperClass(x1); assertThat(new DeclaredType(x2).isCompatibleWith(new DeclaredType(x1))).isTrue(); assertThat(new DeclaredType(x1).isCompatibleWith(new DeclaredType(x1))).isTrue(); assertThat(new DeclaredType(x1).isCompatibleWith(new DeclaredType(x2))).isFalse(); assertThat(new DeclaredType(x1).isCompatibleWith(INT)).isFalse(); DeclaredType emptyUnion = new DeclaredType(new SymbolImpl("Union", "typing.Union")); assertThat(emptyUnion.isCompatibleWith(INT)).isTrue(); }