Program: 19364
Project: 19364
Buggy source:
private EnvTypePair analyzeCallNewFwd(Node expr,TypeEnv inEnv,JSType requiredType,JSType specializedType){
  if (isPropertyTestCall(expr)) {
    return analyzePropertyTestCallFwd(expr,inEnv,specializedType);
  }
  Node callee=expr.getFirstChild();
  if (isFunctionBind(callee,inEnv,true)) {
    return analyzeFunctionBindFwd(expr,inEnv);
  }
  AssertionFunctionSpec assertionFunctionSpec=assertionFunctionsMap.get(callee.getQualifiedName());
  if (assertionFunctionSpec != null) {
    return analyzeAssertionCall(expr,inEnv,assertionFunctionSpec);
  }
  EnvTypePair calleePair=analyzeExprFwd(callee,inEnv,commonTypes.topFunction());
  TypeEnv envAfterCallee=calleePair.env;
  calleePair=mayWarnAboutNullableReferenceAndTighten(callee,calleePair.type,null,envAfterCallee);
  JSType calleeType=calleePair.type;
  if (calleeType.isBottom() || !calleeType.isSubtypeOf(commonTypes.topFunction())) {
    warnings.add(JSError.make(expr,NOT_CALLABLE,calleeType.toString()));
  }
  FunctionType funType=calleeType.getFunTypeIfSingletonObj();
  if (funType == null || funType.isTopFunction() || funType.isQmarkFunction()) {
    return analyzeCallNodeArgsFwdWhenError(expr,envAfterCallee);
  }
 else   if (funType.isLoose()) {
    return analyzeLooseCallNodeFwd(expr,envAfterCallee,requiredType);
  }
 else   if (!isConstructorCall(expr) && funType.isSomeConstructorOrInterface() && (funType.getReturnType().isUnknown() || funType.getReturnType().isUndefined())) {
    warnings.add(JSError.make(expr,CONSTRUCTOR_NOT_CALLABLE,funType.toString()));
    return analyzeCallNodeArgsFwdWhenError(expr,envAfterCallee);
  }
 else   if (expr.isNew()) {
    if (!funType.isSomeConstructorOrInterface() || funType.isInterfaceDefinition()) {
      warnings.add(JSError.make(expr,NOT_A_CONSTRUCTOR,funType.toString()));
      return analyzeCallNodeArgsFwdWhenError(expr,envAfterCallee);
    }
 else     if (funType.isConstructorOfAbstractClass()) {
      warnings.add(JSError.make(expr,CANNOT_INSTANTIATE_ABSTRACT_CLASS,funType.toString()));
      return analyzeCallNodeArgsFwdWhenError(expr,envAfterCallee);
    }
  }
  int maxArity=funType.getMaxArity();
  int minArity=funType.getMinArity();
  int numArgs=expr.getChildCount() - 1;
  if (numArgs < minArity || numArgs > maxArity) {
    warnings.add(JSError.make(expr,WRONG_ARGUMENT_COUNT,getReadableCalleeName(callee),Integer.toString(numArgs),Integer.toString(minArity),"String_Node_Str" + maxArity));
    return analyzeCallNodeArgsFwdWhenError(expr,envAfterCallee);
  }
  FunctionType origFunType=funType;
  if (funType.isGeneric()) {
    Map<String,JSType> typeMap=calcTypeInstantiationFwd(expr,callee.isGetProp() ? callee.getFirstChild() : null,expr.getSecondChild(),funType,envAfterCallee);
    funType=funType.instantiateGenerics(typeMap);
    println("String_Node_Str" + funType);
  }
  List<JSType> argTypes=new ArrayList<>();
  TypeEnv tmpEnv=analyzeCallNodeArgumentsFwd(expr,expr.getSecondChild(),funType,argTypes,envAfterCallee);
  if (callee.isName()) {
    String calleeName=callee.getString();
    if (currentScope.isKnownFunction(calleeName) && !currentScope.isExternalFunction(calleeName)) {
      if (currentScope.isLocalFunDef(calleeName)) {
        tmpEnv=collectTypesForFreeVarsFwd(callee,tmpEnv);
      }
 else       if (!origFunType.isGeneric()) {
        JSType expectedRetType=requiredType;
        println("String_Node_Str",expectedRetType,"String_Node_Str",argTypes);
        DeferredCheck dc;
        if (isConstructorCall(expr)) {
          dc=new DeferredCheck(expr,null,currentScope,currentScope.getScope(calleeName));
          deferredChecks.put(expr,dc);
        }
 else {
          dc=deferredChecks.get(expr);
          if (dc != null) {
            dc.updateReturn(expectedRetType);
          }
 else {
            Preconditions.checkState(!currentScope.hasUndeclaredFormalsOrOuters(),"String_Node_Str",expr);
          }
        }
        if (dc != null) {
          dc.updateArgTypes(argTypes);
        }
      }
    }
  }
  JSType retType=expr.isNew() ? funType.getThisType() : funType.getReturnType();
  if (retType.isSubtypeOf(requiredType)) {
    retType=retType.specialize(specializedType);
  }
  return new EnvTypePair(tmpEnv,retType);
}

Fixed version (ground truth):
private EnvTypePair analyzeCallNewFwd(Node expr,TypeEnv inEnv,JSType requiredType,JSType specializedType){
  if (isPropertyTestCall(expr)) {
    return analyzePropertyTestCallFwd(expr,inEnv,specializedType);
  }
  Node callee=expr.getFirstChild();
  if (isFunctionBind(callee,inEnv,true)) {
    return analyzeFunctionBindFwd(expr,inEnv);
  }
  AssertionFunctionSpec assertionFunctionSpec=assertionFunctionsMap.get(callee.getQualifiedName());
  if (assertionFunctionSpec != null) {
    return analyzeAssertionCall(expr,inEnv,assertionFunctionSpec);
  }
  EnvTypePair calleePair=analyzeExprFwd(callee,inEnv,commonTypes.topFunction());
  TypeEnv envAfterCallee=calleePair.env;
  calleePair=mayWarnAboutNullableReferenceAndTighten(callee,calleePair.type,null,envAfterCallee);
  JSType calleeType=calleePair.type;
  if (calleeType.isBottom() || !calleeType.isSubtypeOf(commonTypes.topFunction())) {
    warnings.add(JSError.make(expr,NOT_CALLABLE,calleeType.toString()));
  }
  FunctionType funType=calleeType.getFunTypeIfSingletonObj();
  if (funType == null || funType.isTopFunction() || funType.isQmarkFunction()) {
    return analyzeCallNodeArgsFwdWhenError(expr,envAfterCallee);
  }
 else   if (funType.isLoose()) {
    return analyzeLooseCallNodeFwd(expr,envAfterCallee,requiredType);
  }
 else   if (!isConstructorCall(expr) && funType.isSomeConstructorOrInterface() && (funType.getReturnType().isUnknown() || funType.getReturnType().isUndefined())) {
    warnings.add(JSError.make(expr,CONSTRUCTOR_NOT_CALLABLE,funType.toString()));
    return analyzeCallNodeArgsFwdWhenError(expr,envAfterCallee);
  }
 else   if (expr.isNew()) {
    if (!funType.isSomeConstructorOrInterface() || funType.isInterfaceDefinition()) {
      warnings.add(JSError.make(expr,NOT_A_CONSTRUCTOR,funType.toString()));
      return analyzeCallNodeArgsFwdWhenError(expr,envAfterCallee);
    }
 else     if (funType.isConstructorOfAbstractClass()) {
      warnings.add(JSError.make(expr,CANNOT_INSTANTIATE_ABSTRACT_CLASS,funType.toString()));
      return analyzeCallNodeArgsFwdWhenError(expr,envAfterCallee);
    }
  }
  int maxArity=funType.getMaxArity();
  int minArity=funType.getMinArity();
  int numArgs=expr.getChildCount() - 1;
  if (numArgs < minArity || numArgs > maxArity) {
    warnings.add(JSError.make(expr,WRONG_ARGUMENT_COUNT,getReadableCalleeName(callee),Integer.toString(numArgs),Integer.toString(minArity),"String_Node_Str" + maxArity));
    return analyzeCallNodeArgsFwdWhenError(expr,envAfterCallee);
  }
  FunctionType origFunType=funType;
  if (funType.isGeneric()) {
    Map<String,JSType> typeMap=calcTypeInstantiationFwd(expr,callee.isGetProp() ? callee.getFirstChild() : null,expr.getSecondChild(),funType,envAfterCallee);
    funType=funType.instantiateGenerics(typeMap);
    println("String_Node_Str",funType);
  }
  List<JSType> argTypes=new ArrayList<>();
  TypeEnv tmpEnv=analyzeCallNodeArgumentsFwd(expr,expr.getSecondChild(),funType,argTypes,envAfterCallee);
  if (callee.isName()) {
    String calleeName=callee.getString();
    if (currentScope.isKnownFunction(calleeName) && !currentScope.isExternalFunction(calleeName)) {
      if (currentScope.isLocalFunDef(calleeName)) {
        tmpEnv=collectTypesForFreeVarsFwd(callee,tmpEnv);
      }
 else       if (!origFunType.isGeneric()) {
        JSType expectedRetType=requiredType;
        println("String_Node_Str",expectedRetType,"String_Node_Str",argTypes);
        DeferredCheck dc;
        if (isConstructorCall(expr)) {
          dc=new DeferredCheck(expr,null,currentScope,currentScope.getScope(calleeName));
          deferredChecks.put(expr,dc);
        }
 else {
          dc=deferredChecks.get(expr);
          if (dc != null) {
            dc.updateReturn(expectedRetType);
          }
 else {
            Preconditions.checkState(!currentScope.hasUndeclaredFormalsOrOuters(),"String_Node_Str",expr);
          }
        }
        if (dc != null) {
          dc.updateArgTypes(argTypes);
        }
      }
    }
  }
  JSType retType=expr.isNew() ? funType.getThisType() : funType.getReturnType();
  if (retType.isSubtypeOf(requiredType)) {
    retType=retType.specialize(specializedType);
  }
  return new EnvTypePair(tmpEnv,retType);
}