Program: 19323
Project: 19323
Buggy source:
private EnvTypePair analyzeFunctionBindFwd(Node call,TypeEnv inEnv){
  Preconditions.checkArgument(call.isCall());
  Bind bindComponents=this.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,pair.type.toString()));
  }
  if (boundFunType == null || boundFunType.isTopFunction() || boundFunType.isQmarkFunction() || boundFunType.isLoose()) {
    return analyzeCallNodeArgsFwdWhenError(call,env);
  }
  if (boundFunType.isSomeConstructorOrInterface()) {
    warnings.add(JSError.make(call,CANNOT_BIND_CTOR));
    return new EnvTypePair(env,UNKNOWN);
  }
  int callChildCount=call.getChildCount();
  if (NodeUtil.isGoogBind(call.getFirstChild()) && callChildCount <= 2 || !NodeUtil.isGoogPartial(call.getFirstChild()) && callChildCount == 1) {
    warnings.add(JSError.make(call,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,WRONG_ARGUMENT_COUNT,getReadableCalleeName(call.getFirstChild()),Integer.toString(numArgs),"String_Node_Str","String_Node_Str" + maxArity));
    return analyzeCallNodeArgsFwdWhenError(call,inEnv);
  }
  Node receiver=bindComponents.thisValue;
  if (boundFunType.isGeneric()) {
    Map<String,JSType> typeMap=calcTypeInstantiationFwd(call,receiver,bindComponents.parameters,boundFunType,env);
    boundFunType=boundFunType.instantiateGenerics(typeMap);
  }
  FunctionTypeBuilder builder=new FunctionTypeBuilder(this.commonTypes);
  if (receiver != null) {
    JSType reqThisType=boundFunType.getThisType();
    if (reqThisType == null || boundFunType.isSomeConstructorOrInterface()) {
      reqThisType=JSType.join(NULL,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,errorMsgWithTypeDiff(reqThisType,pair.type)));
    }
  }
  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=this.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,pair.type.toString()));
  }
  if (boundFunType == null || boundFunType.isTopFunction() || boundFunType.isQmarkFunction() || boundFunType.isLoose()) {
    return analyzeCallNodeArgsFwdWhenError(call,env);
  }
  if (boundFunType.isSomeConstructorOrInterface()) {
    warnings.add(JSError.make(call,CANNOT_BIND_CTOR));
    return new EnvTypePair(env,UNKNOWN);
  }
  int callChildCount=call.getChildCount();
  if ((NodeUtil.isGoogBind(call.getFirstChild()) && callChildCount <= 2) || (!NodeUtil.isGoogPartial(call.getFirstChild()) && callChildCount == 1)) {
    warnings.add(JSError.make(call,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,WRONG_ARGUMENT_COUNT,getReadableCalleeName(call.getFirstChild()),Integer.toString(numArgs),"String_Node_Str","String_Node_Str" + maxArity));
    return analyzeCallNodeArgsFwdWhenError(call,inEnv);
  }
  Node receiver=bindComponents.thisValue;
  if (boundFunType.isGeneric()) {
    Map<String,JSType> typeMap=calcTypeInstantiationFwd(call,receiver,bindComponents.parameters,boundFunType,env);
    boundFunType=boundFunType.instantiateGenerics(typeMap);
  }
  FunctionTypeBuilder builder=new FunctionTypeBuilder(this.commonTypes);
  if (receiver != null) {
    JSType reqThisType=boundFunType.getThisType();
    if (reqThisType == null || boundFunType.isSomeConstructorOrInterface()) {
      reqThisType=JSType.join(NULL,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,errorMsgWithTypeDiff(reqThisType,pair.type)));
    }
  }
  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()));
}