/** * Gets the least supertype of {@code this} and {@code that}. * The least supertype is the join (∨) or supremum of both types in the * type lattice.<p> * Examples: * <ul> * <li><code>number ∨ *</code> = {@code *}</li> * <li><code>number ∨ Object</code> = {@code (number, Object)}</li> * <li><code>Number ∨ Object</code> = {@code Object}</li> * </ul> * @return <code>this ∨ that</code> */ public JSType getLeastSupertype(JSType that) { if (that.isUnionType()) { // Union types have their own implementation of getLeastSupertype. return that.toMaybeUnionType().getLeastSupertype(this); } return getLeastSupertype(this, that); }
@Override public JSType getLeastSupertype(JSType that) { if (!that.isUnknownType() && !that.isUnionType()) { for (JSType alternate : alternatesWithoutStucturalTyping) { if (!alternate.isUnknownType() && that.isSubtype(alternate)) { return this; } } } return getLeastSupertype(this, that); }
/** * Gets the least supertype of {@code this} and {@code that}. The least supertype is the join * (∨) or supremum of both types in the type lattice. * * <p>Examples: * * <ul> * <li><code>number ∨ *</code> = {@code *} * <li><code>number ∨ Object</code> = {@code (number, Object)} * <li><code>Number ∨ Object</code> = {@code Object} * </ul> * * @return <code>this ∨ that</code> */ @SuppressWarnings("AmbiguousMethodReference") public JSType getLeastSupertype(JSType that) { if (areIdentical(this, that)) { return this; } that = filterNoResolvedType(that); if (that.isUnionType()) { // Union types have their own implementation of getLeastSupertype. return that.toMaybeUnionType().getLeastSupertype(this); } return getLeastSupertype(this, that); }