Program: 27529
Project: 27529
Buggy source:
private EnvTypePair analyzeFunctionBindFwd(Node call,TypeEnv inEnv){
  Preconditions.checkArgument(call.isCall());
  Bind bindComponents=convention.describeFunctionBind(call,true,false);
  Node boundFunNode=bindComponents.target;
  EnvTypePair pair=analyzeExprFwd(boundFunNode,inEnv);
  TypeEnv env=pair.env;
  FunctionType boundFunType=pair.type.getFunTypeIfSingletonObj();
  if (!pair.type.isSubtypeOf(commonTypes.topFunction())) {
    warnings.add(JSError.make(boundFunNode,GOOG_BIND_EXPECTS_FUNCTION));
  }
  if (boundFunType == null || boundFunType.isTopFunction() || boundFunType.isQmarkFunction() || boundFunType.isLoose()) {
    return analyzeCallNodeArgsFwdWhenError(call,env);
  }
  if (boundFunType.isConstructor()) {
    warnings.add(JSError.make(call,CANNOT_BIND_CTOR));
    return new EnvTypePair(env,JSType.UNKNOWN);
  }
  if (NodeUtil.isGoogBind(call) && call.getChildCount() <= 2 || !NodeUtil.isGoogPartial(call) && call.getChildCount() == 1) {
    warnings.add(JSError.make(call,TypeCheck.WRONG_ARGUMENT_COUNT,getReadableCalleeName(call.getFirstChild()),"String_Node_Str","String_Node_Str","String_Node_Str"));
  }
  int maxArity=boundFunType.hasRestFormals() ? Integer.MAX_VALUE : boundFunType.getMaxArity();
  int numArgs=bindComponents.getBoundParameterCount();
  if (numArgs > maxArity) {
    warnings.add(JSError.make(call,TypeCheck.WRONG_ARGUMENT_COUNT,getReadableCalleeName(call.getFirstChild()),Integer.toString(numArgs),"String_Node_Str","String_Node_Str" + maxArity));
    return analyzeCallNodeArgsFwdWhenError(call,inEnv);
  }
  if (boundFunType.isGeneric()) {
    Map<String,JSType> typeMap=calcTypeInstantiationFwd(call,bindComponents.parameters,boundFunType,env);
    boundFunType=boundFunType.instantiateGenerics(typeMap);
  }
  FunctionTypeBuilder builder=new FunctionTypeBuilder();
  Node receiver=bindComponents.thisValue;
  if (receiver != null) {
    JSType reqThisType=boundFunType.getThisType();
    if (reqThisType == null || boundFunType.isConstructor()) {
      reqThisType=JSType.join(JSType.NULL,JSType.TOP_OBJECT);
    }
    pair=analyzeExprFwd(receiver,env,reqThisType);
    env=pair.env;
    if (!pair.type.isSubtypeOf(reqThisType)) {
      warnings.add(JSError.make(call,INVALID_THIS_TYPE_IN_BIND,pair.type.toString(),reqThisType.toString()));
    }
  }
  env=analyzeCallNodeArgumentsFwd(call,bindComponents.parameters,boundFunType,new ArrayList<JSType>(),env);
  for (int j=numArgs; j < boundFunType.getMaxArityWithoutRestFormals(); j++) {
    JSType formalType=boundFunType.getFormalType(j);
    if (boundFunType.isRequiredArg(j)) {
      builder.addReqFormal(formalType);
    }
 else {
      builder.addOptFormal(formalType);
    }
  }
  if (boundFunType.hasRestFormals()) {
    builder.addRestFormals(boundFunType.getRestFormalsType());
  }
  return new EnvTypePair(env,commonTypes.fromFunctionType(builder.addRetType(boundFunType.getReturnType()).buildFunction()));
}

Fixed version (ground truth):
private EnvTypePair analyzeFunctionBindFwd(Node call,TypeEnv inEnv){
  Preconditions.checkArgument(call.isCall());
  Bind bindComponents=convention.describeFunctionBind(call,true,false);
  Node boundFunNode=bindComponents.target;
  EnvTypePair pair=analyzeExprFwd(boundFunNode,inEnv);
  TypeEnv env=pair.env;
  FunctionType boundFunType=pair.type.getFunTypeIfSingletonObj();
  if (!pair.type.isSubtypeOf(commonTypes.topFunction())) {
    warnings.add(JSError.make(boundFunNode,GOOG_BIND_EXPECTS_FUNCTION));
  }
  if (boundFunType == null || boundFunType.isTopFunction() || boundFunType.isQmarkFunction() || boundFunType.isLoose()) {
    return analyzeCallNodeArgsFwdWhenError(call,env);
  }
  if (boundFunType.isConstructor()) {
    warnings.add(JSError.make(call,CANNOT_BIND_CTOR));
    return new EnvTypePair(env,JSType.UNKNOWN);
  }
  if (NodeUtil.isGoogBind(call.getFirstChild()) && call.getChildCount() <= 2 || !NodeUtil.isGoogPartial(call.getFirstChild()) && call.getChildCount() == 1) {
    warnings.add(JSError.make(call,TypeCheck.WRONG_ARGUMENT_COUNT,getReadableCalleeName(call.getFirstChild()),"String_Node_Str","String_Node_Str","String_Node_Str"));
  }
  int maxArity=boundFunType.hasRestFormals() ? Integer.MAX_VALUE : boundFunType.getMaxArity();
  int numArgs=bindComponents.getBoundParameterCount();
  if (numArgs > maxArity) {
    warnings.add(JSError.make(call,TypeCheck.WRONG_ARGUMENT_COUNT,getReadableCalleeName(call.getFirstChild()),Integer.toString(numArgs),"String_Node_Str","String_Node_Str" + maxArity));
    return analyzeCallNodeArgsFwdWhenError(call,inEnv);
  }
  if (boundFunType.isGeneric()) {
    Map<String,JSType> typeMap=calcTypeInstantiationFwd(call,bindComponents.parameters,boundFunType,env);
    boundFunType=boundFunType.instantiateGenerics(typeMap);
  }
  FunctionTypeBuilder builder=new FunctionTypeBuilder();
  Node receiver=bindComponents.thisValue;
  if (receiver != null) {
    JSType reqThisType=boundFunType.getThisType();
    if (reqThisType == null || boundFunType.isConstructor()) {
      reqThisType=JSType.join(JSType.NULL,JSType.TOP_OBJECT);
    }
    pair=analyzeExprFwd(receiver,env,reqThisType);
    env=pair.env;
    if (!pair.type.isSubtypeOf(reqThisType)) {
      warnings.add(JSError.make(call,INVALID_THIS_TYPE_IN_BIND,pair.type.toString(),reqThisType.toString()));
    }
  }
  env=analyzeCallNodeArgumentsFwd(call,bindComponents.parameters,boundFunType,new ArrayList<JSType>(),env);
  for (int j=numArgs; j < boundFunType.getMaxArityWithoutRestFormals(); j++) {
    JSType formalType=boundFunType.getFormalType(j);
    if (boundFunType.isRequiredArg(j)) {
      builder.addReqFormal(formalType);
    }
 else {
      builder.addOptFormal(formalType);
    }
  }
  if (boundFunType.hasRestFormals()) {
    builder.addRestFormals(boundFunType.getRestFormalsType());
  }
  return new EnvTypePair(env,commonTypes.fromFunctionType(builder.addRetType(boundFunType.getReturnType()).buildFunction()));
}