/** * Creates an arrow type, an abstract representation of the parameters * and return value of a function. * * @param parametersNode the parameters' types, formatted as a Node with * param names and optionality info. * @param returnType the function's return type */ ArrowType createArrowType(Node parametersNode, JSType returnType) { return new ArrowType(this, parametersNode, returnType); }
public final boolean hasEqualCallType(FunctionType otherType) { return this.call.checkArrowEquivalenceHelper( otherType.call, EquivalenceMethod.IDENTITY, EqCache.create()); }
ArrowType(JSTypeRegistry registry, Node parameters, JSType returnType, boolean returnTypeInferred) { super(registry); this.parameters = parameters == null ? registry.createParametersWithVarArgs(getNativeType(UNKNOWN_TYPE)) : parameters; this.returnType = returnType == null ? getNativeType(UNKNOWN_TYPE) : returnType; this.returnTypeInferred = returnTypeInferred; }
FunctionType other, boolean leastSuper) { Node newParamsNode = null; if (call.hasEqualParameters(other.call, EquivalenceMethod.IDENTITY, EqCache.create())) { newParamsNode = call.parameters; } else { new ArrowType( registry, newParamsNode, newReturnType, newReturnTypeInferred), newTypeOfThis, null, false, false);
@Override public boolean isSubtype(JSType that) { return isSubtype(that, ImplCache.create(), SubtypingMode.NORMAL); }
boolean checkArrowEquivalenceHelper( ArrowType that, EquivalenceMethod eqMethod, EqCache eqCache) { // Please keep this method in sync with the hashCode() method below. if (!returnType.checkEquivalenceHelper( that.returnType, eqMethod, eqCache)) { return false; } return hasEqualParameters(that, eqMethod, eqCache); }
@Override public boolean hasAnyTemplateTypesInternal() { return returnType.hasAnyTemplateTypes() || hasTemplatedParameterType(); }
@Override JSType resolveInternal(ErrorReporter t, StaticTypedScope<JSType> scope) { returnType = safeResolve(returnType, t, scope); if (parameters != null) { for (Node paramNode = parameters.getFirstChild(); paramNode != null; paramNode = paramNode.getNext()) { paramNode.setJSType(paramNode.getJSType().resolve(t, scope)); } } return this; }
@Override public boolean hasAnyTemplateTypesInternal() { return getTemplateTypeMap().numUnfilledTemplateKeys() > 0 || typeOfThis.hasAnyTemplateTypes() || call.hasAnyTemplateTypes(); }
@Override public int hashCode() { return isInterface() ? getReferenceName().hashCode() : call.hashCode(); }
!this.call.hasUnknownParamsOrReturn() && !that.call.hasUnknownParamsOrReturn()) {
@Override public boolean isSubtype(JSType that) { return isSubtype(that, ImplCache.create()); }
boolean checkArrowEquivalenceHelper( ArrowType that, EquivalenceMethod eqMethod, EqCache eqCache) { // Please keep this method in sync with the hashCode() method below. if (!returnType.checkEquivalenceHelper( that.returnType, eqMethod, eqCache)) { return false; } return hasEqualParameters(that, eqMethod, eqCache); }
@Override public boolean hasAnyTemplateTypesInternal() { return returnType.hasAnyTemplateTypes() || hasTemplatedParameterType(); }
@Override JSType resolveInternal(ErrorReporter reporter) { returnType = safeResolve(returnType, reporter); if (parameters != null) { for (Node paramNode = parameters.getFirstChild(); paramNode != null; paramNode = paramNode.getNext()) { paramNode.setJSType(paramNode.getJSType().resolve(reporter)); } } return this; }
@Override final boolean hasAnyTemplateTypesInternal() { return getTemplateTypeMap().numUnfilledTemplateKeys() > 0 || typeOfThis.hasAnyTemplateTypes() || call.hasAnyTemplateTypes(); }
@Override int recursionUnsafeHashCode() { int hc = kind.hashCode(); switch (kind) { case CONSTRUCTOR: return 31 * hc + System.identityHashCode(this); // constructors use identity semantics case INTERFACE: return 31 * hc + getReferenceName().hashCode(); case ORDINARY: hc = 31 * hc + typeOfThis.hashCode(); hc = 31 * hc + call.hashCode(); return hc; default: throw new AssertionError(); } }
&& !this.call.hasUnknownParamsOrReturn() && !that.call.hasUnknownParamsOrReturn()) {
/** * Creates an arrow type with an unknown return type. * * @param parametersNode the parameters' types, formatted as a Node with * param names and optionality info. */ ArrowType createArrowType(Node parametersNode) { return new ArrowType(this, parametersNode, null); }
@Override protected boolean isSubtype( JSType that, ImplCache implicitImplCache, SubtypingMode subtypingMode) { if (JSType.isSubtypeHelper(this, that, implicitImplCache, subtypingMode)) { return true; } if (that.isFunctionType()) { FunctionType other = that.toMaybeFunctionType(); if (other.isInterface()) { // Any function can be assigned to an interface function. return true; } if (isInterface()) { // An interface function cannot be assigned to anything. return false; } return shouldTreatThisTypesAsCovariant(other, implicitImplCache) && this.call.isSubtype(other.call, implicitImplCache, subtypingMode); } return getNativeType(JSTypeNative.FUNCTION_PROTOTYPE) .isSubtype(that, implicitImplCache, subtypingMode); }