Program: 27546
Project: 27546
Buggy source:
static FunctionType join(FunctionType f1,FunctionType f2){
  if (f1 == null) {
    return f2;
  }
 else   if (f2 == null || f1.equals(f2)) {
    return f1;
  }
 else   if (f1.isTopFunction() || f2.isTopFunction()) {
    return TOP_FUNCTION;
  }
  if (f1.isLoose() || f2.isLoose()) {
    return FunctionType.looseJoin(f1,f2);
  }
  if (f1.isGeneric() && f2.isSubtypeOf(f1)) {
    return f1;
  }
 else   if (f2.isGeneric() && f1.isSubtypeOf(f2)) {
    return f2;
  }
  if (f1.isGeneric()) {
    f1=instantiateGenericsWithUnknown(f1);
  }
  if (f2.isGeneric()) {
    f2=instantiateGenericsWithUnknown(f2);
  }
  FunctionTypeBuilder builder=new FunctionTypeBuilder();
  int maxRequiredArity=Math.max(f1.requiredFormals.size(),f2.requiredFormals.size());
  for (int i=0; i < maxRequiredArity; i++) {
    JSType reqFormal=nullAcceptingMeet(f1.getFormalType(i),f2.getFormalType(i));
    builder.addReqFormal(reqFormal);
  }
  int maxTotalArity=Math.max(f1.requiredFormals.size() + f1.optionalFormals.size(),f2.requiredFormals.size() + f2.optionalFormals.size());
  for (int i=maxRequiredArity; i < maxTotalArity; i++) {
    JSType optFormal=nullAcceptingMeet(f1.getFormalType(i),f2.getFormalType(i));
    builder.addOptFormal(optFormal);
  }
  if (f1.restFormals != null && f2.restFormals != null) {
    builder.addRestFormals(nullAcceptingMeet(f1.restFormals,f2.restFormals));
  }
  builder.addRetType(JSType.join(f1.returnType,f2.returnType));
  builder.addNominalType(NominalType.pickSuperclass(f1.nominalType,f2.nominalType));
  builder.addReceiverType(NominalType.pickSuperclass(f1.receiverType,f2.receiverType));
  return builder.buildFunction();
}

Fixed version (ground truth):
static FunctionType join(FunctionType f1,FunctionType f2){
  if (f1 == null) {
    return f2;
  }
 else   if (f2 == null || f1.equals(f2)) {
    return f1;
  }
 else   if (f1.isQmarkFunction() || f2.isQmarkFunction()) {
    return QMARK_FUNCTION;
  }
 else   if (f1.isTopFunction() || f2.isTopFunction()) {
    return TOP_FUNCTION;
  }
  if (f1.isLoose() || f2.isLoose()) {
    return looseJoin(f1,f2);
  }
  if (f1.isGeneric() && f2.isSubtypeOf(f1)) {
    return f1;
  }
 else   if (f2.isGeneric() && f1.isSubtypeOf(f2)) {
    return f2;
  }
  if (f1.isGeneric()) {
    f1=instantiateGenericsWithUnknown(f1);
  }
  if (f2.isGeneric()) {
    f2=instantiateGenericsWithUnknown(f2);
  }
  FunctionTypeBuilder builder=new FunctionTypeBuilder();
  int maxRequiredArity=Math.max(f1.requiredFormals.size(),f2.requiredFormals.size());
  for (int i=0; i < maxRequiredArity; i++) {
    JSType reqFormal=nullAcceptingMeet(f1.getFormalType(i),f2.getFormalType(i));
    builder.addReqFormal(reqFormal);
  }
  int maxTotalArity=Math.max(f1.requiredFormals.size() + f1.optionalFormals.size(),f2.requiredFormals.size() + f2.optionalFormals.size());
  for (int i=maxRequiredArity; i < maxTotalArity; i++) {
    JSType optFormal=nullAcceptingMeet(f1.getFormalType(i),f2.getFormalType(i));
    builder.addOptFormal(optFormal);
  }
  if (f1.restFormals != null && f2.restFormals != null) {
    builder.addRestFormals(nullAcceptingMeet(f1.restFormals,f2.restFormals));
  }
  builder.addRetType(JSType.join(f1.returnType,f2.returnType));
  builder.addNominalType(NominalType.pickSuperclass(f1.nominalType,f2.nominalType));
  builder.addReceiverType(NominalType.pickSuperclass(f1.receiverType,f2.receiverType));
  return builder.buildFunction();
}