src/com/google/javascript/jscomp/TypeCheck.java
/**
   * Visits a CALL node.
   *
   * @param t The node traversal object that supplies context, such as the
   * scope chain to use in name lookups as well as error reporting.
   * @param n The node being visited.
   */
Visits a CALL node.
@param t The node traversal object that supplies context, such as the
scope chain to use in name lookups as well as error reporting.
@param n The node being visited.
Visits a CALL node . @param t The node traversal object that supplies context such as the scope chain to use in name lookups as well as error reporting . @param n The node being visited .
private void visitCall(NodeTraversal t, Node n) {
    checkCallConventions(t, n);
    Node child = n.getFirstChild();
    JSType childType = getJSType(child).restrictByNotNullOrUndefined();
    if (!childType.canBeCalled()) {
      report(t, n, NOT_CALLABLE, childType.toString());
      ensureTyped(n);
      return;
    }
    if (childType.isFunctionType()) {
      FunctionType functionType = childType.toMaybeFunctionType();
      if (functionType.isConstructor()
          && !functionType.isNativeObjectType()
          && (functionType.getReturnType().isUnknownType()
              || functionType.getReturnType().isVoidType())
          && !n.getFirstChild().isSuper()) {
        report(t, n, CONSTRUCTOR_NOT_CALLABLE, childType.toString());
      }
      if (functionType.isOrdinaryFunction()
          && !functionType.getTypeOfThis().isUnknownType()
          && !(functionType.getTypeOfThis().toObjectType() != null
              && functionType.getTypeOfThis().toObjectType().isNativeObjectType())
          && !(child.isGetElem() || child.isGetProp())) {
        report(t, n, EXPECTED_THIS_TYPE, functionType.toString());
      }
      checkAbstractMethodCall(t, n);
      visitArgumentList(t, n, functionType);
      ensureTyped(n, functionType.getReturnType());
    } else {
      ensureTyped(n);
    }
  }
private void visitCall ( NodeTraversal t , Node n ) { checkCallConventions ( t , n ) ; Node child = n . getFirstChild ( ) ; JSType childType = getJSType ( child ) . restrictByNotNullOrUndefined ( ) ; if ( ! childType . canBeCalled ( ) ) { report ( t , n , NOT_CALLABLE , childType . toString ( ) ) ; ensureTyped ( n ) ; return ; } if ( childType . isFunctionType ( ) ) { FunctionType functionType = childType . toMaybeFunctionType ( ) ; if ( functionType . isConstructor ( ) && ! functionType . isNativeObjectType ( ) && ( functionType . getReturnType ( ) . isUnknownType ( ) || functionType . getReturnType ( ) . isVoidType ( ) ) && ! n . getFirstChild ( ) . isSuper ( ) ) { report ( t , n , CONSTRUCTOR_NOT_CALLABLE , childType . toString ( ) ) ; } if ( functionType . isOrdinaryFunction ( ) && ! functionType . getTypeOfThis ( ) . isUnknownType ( ) && ! ( functionType . getTypeOfThis ( ) . toObjectType ( ) != null && functionType . getTypeOfThis ( ) . toObjectType ( ) . isNativeObjectType ( ) ) && ! ( child . isGetElem ( ) || child . isGetProp ( ) ) ) { report ( t , n , EXPECTED_THIS_TYPE , functionType . toString ( ) ) ; } checkAbstractMethodCall ( t , n ) ; visitArgumentList ( t , n , functionType ) ; ensureTyped ( n , functionType . getReturnType ( ) ) ; } else { ensureTyped ( n ) ; } }
Visits a CALL node.
Visits a CALL node .
// A couple of types can be called as if they were functions. // If it is a function type, then validate parameters. // Non-native constructors should not be called directly // unless they specify a return type // Functions with explicit 'this' types must be called in a GETPROP // or GETELEM. // TODO(nicksantos): Add something to check for calls of RegExp objects, // which is not supported by IE. Either say something about the return type // or warn about the non-portability of the call or both.