Program: 27548
Project: 27548
Buggy source:
static FunctionType meet(FunctionType f1,FunctionType f2){
  if (f1 == null || f2 == null) {
    return null;
  }
 else   if (f2.isTopFunction() || f1.equals(f2)) {
    return f1;
  }
 else   if (f1.isTopFunction()) {
    return f2;
  }
  if (f1.isLoose() || f2.isLoose()) {
    return FunctionType.looseJoin(f1,f2);
  }
  if (f1.isGeneric() && f1.isSubtypeOf(f2)) {
    return f1;
  }
 else   if (f2.isGeneric() && f2.isSubtypeOf(f1)) {
    return f2;
  }
  if (f1.isGeneric()) {
    f1=instantiateGenericsWithUnknown(f1);
  }
  if (f2.isGeneric()) {
    f2=instantiateGenericsWithUnknown(f2);
  }
  FunctionTypeBuilder builder=new FunctionTypeBuilder();
  int minRequiredArity=Math.min(f1.requiredFormals.size(),f2.requiredFormals.size());
  for (int i=0; i < minRequiredArity; i++) {
    builder.addReqFormal(JSType.nullAcceptingJoin(f1.getFormalType(i),f2.getFormalType(i)));
  }
  int maxTotalArity=Math.max(f1.requiredFormals.size() + f1.optionalFormals.size(),f2.requiredFormals.size() + f2.optionalFormals.size());
  for (int i=minRequiredArity; i < maxTotalArity; i++) {
    builder.addOptFormal(JSType.nullAcceptingJoin(f1.getFormalType(i),f2.getFormalType(i)));
  }
  if (f1.restFormals != null || f2.restFormals != null) {
    builder.addRestFormals(JSType.nullAcceptingJoin(f1.restFormals,f2.restFormals));
  }
  JSType retType=JSType.meet(f1.returnType,f2.returnType);
  if (retType.isBottom()) {
    return BOTTOM_FUNCTION;
  }
  builder.addRetType(retType);
  builder.addNominalType(NominalType.pickSubclass(f1.nominalType,f2.nominalType));
  builder.addReceiverType(NominalType.pickSubclass(f1.receiverType,f2.receiverType));
  return builder.buildFunction();
}

Fixed version (ground truth):
static FunctionType meet(FunctionType f1,FunctionType f2){
  if (f1 == null || f2 == null) {
    return null;
  }
 else   if (f2.isTopFunction() || f1.equals(f2)) {
    return f1;
  }
 else   if (f1.isTopFunction()) {
    return f2;
  }
  if (f1.isLoose() || f2.isLoose()) {
    return looseJoin(f1,f2);
  }
  if (f1.isGeneric() && f1.isSubtypeOf(f2)) {
    return f1;
  }
 else   if (f2.isGeneric() && f2.isSubtypeOf(f1)) {
    return f2;
  }
  if (f1.isGeneric()) {
    f1=instantiateGenericsWithUnknown(f1);
  }
  if (f2.isGeneric()) {
    f2=instantiateGenericsWithUnknown(f2);
  }
  FunctionTypeBuilder builder=new FunctionTypeBuilder();
  int minRequiredArity=Math.min(f1.requiredFormals.size(),f2.requiredFormals.size());
  for (int i=0; i < minRequiredArity; i++) {
    builder.addReqFormal(JSType.nullAcceptingJoin(f1.getFormalType(i),f2.getFormalType(i)));
  }
  int maxTotalArity=Math.max(f1.requiredFormals.size() + f1.optionalFormals.size(),f2.requiredFormals.size() + f2.optionalFormals.size());
  for (int i=minRequiredArity; i < maxTotalArity; i++) {
    builder.addOptFormal(JSType.nullAcceptingJoin(f1.getFormalType(i),f2.getFormalType(i)));
  }
  if (f1.restFormals != null || f2.restFormals != null) {
    builder.addRestFormals(JSType.nullAcceptingJoin(f1.restFormals,f2.restFormals));
  }
  JSType retType=JSType.meet(f1.returnType,f2.returnType);
  if (retType.isBottom()) {
    return BOTTOM_FUNCTION;
  }
  builder.addRetType(retType);
  builder.addNominalType(NominalType.pickSubclass(f1.nominalType,f2.nominalType));
  builder.addReceiverType(NominalType.pickSubclass(f1.receiverType,f2.receiverType));
  return builder.buildFunction();
}