nus-yam/ex-repair huggingface dataset:
Program: 132531
Project: 132531
Buggy source:
/** 
 * Use ANTLR to parse the input and get the Tree
 * @throws IOException 
 */
private static SwiftAST runANTLR(ANTLRInputStream input,LineMapping lineMap){
  ExMLexer lexer=new ExMLexer(input);
  lexer.lineMap=lineMap;
  CommonTokenStream tokens=new CommonTokenStream(lexer);
  ExMParser parser=new ExMParser(tokens);
  parser.lineMap=lineMap;
  parser.setTreeAdaptor(new SwTreeAdaptor());
  ExMParser.program_return program=null;
  try {
    program=parser.program();
  }
 catch (  RecognitionException e) {
    e.printStackTrace();
    System.out.println("String_Node_Str");
    throw new STCFatal(ExitCode.ERROR_INTERNAL.code());
  }
  if (parser.parserError) {
    System.err.println("String_Node_Str");
    throw new STCFatal(ExitCode.ERROR_USER.code());
  }
  if (program == null)   throw new STCRuntimeError("String_Node_Str");
  SwiftAST tree=(SwiftAST)program.getTree();
  return tree;
}

Fixed version (ground truth):
/** 
 * Use ANTLR to parse the input and get the Tree
 * @throws IOException
 */
private static SwiftAST runANTLR(ANTLRInputStream input,LineMapping lineMap){
  ExMLexer lexer=new ExMLexer(input);
  lexer.lineMap=lineMap;
  CommonTokenStream tokens=new CommonTokenStream(lexer);
  ExMParser parser=new ExMParser(tokens);
  parser.lineMap=lineMap;
  parser.setTreeAdaptor(new SwTreeAdaptor());
  ExMParser.program_return program=null;
  try {
    program=parser.program();
  }
 catch (  RecognitionException e) {
    e.printStackTrace();
    System.out.println("String_Node_Str");
    throw new STCFatal(ExitCode.ERROR_INTERNAL.code());
  }
  if (parser.parserError) {
    System.err.println("String_Node_Str");
    throw new STCFatal(ExitCode.ERROR_USER.code());
  }
  if (program == null)   throw new STCRuntimeError("String_Node_Str");
  SwiftAST tree=(SwiftAST)program.getTree();
  return tree;
}
Program: 132533
Project: 132533
Buggy source:
private void compileTopLevel(GlobalContext context,LocatedModule mainModule) throws UserException, UndefinedFunctionException, ModuleLoadException {
  LocalContext topLevelContext=LocalContext.topLevelContext(context);
  Pair<ParsedModule,Boolean> loadedMainModule=modules.loadIfNeeded(context,mainModule);
  assert(!loadedMainModule.val2);
  varAnalyzer.walkTopLevel(context,loadedMainModule.val1);
  backend.startFunction(FnID.ENTRY_FUNCTION,Var.NONE,Var.NONE,ExecTarget.syncControl());
  loadModule(context,topLevelContext,FrontendPass.COMPILE_TOPLEVEL,mainModule);
  List<FnOverload> mainOverloads=context.lookupFunction(Constants.MAIN_FUNCTION);
  if (mainOverloads.size() == 1) {
    FnID mainID=mainOverloads.get(0).id;
    backend.functionCall(mainID,Arg.NONE,Var.NONE,ExecTarget.syncControl(),new TaskProps());
  }
 else   if (mainOverloads.size() >= 2) {
    throw new DoubleDefineException(context,"String_Node_Str" + Constants.MAIN_FUNCTION);
  }
  backend.endFunction();
}

Fixed version (ground truth):
private void compileTopLevel(GlobalContext context,LocatedModule mainModule,LocatedModule builtins) throws UserException {
  LocalContext topLevelContext=LocalContext.topLevelContext(context);
  List<LocatedModule> locatedModules=Arrays.asList(builtins,mainModule);
  List<ParsedModule> parsedModules=new ArrayList<ParsedModule>();
  for (  LocatedModule module : locatedModules) {
    Pair<ParsedModule,Boolean> loaded=modules.loadIfNeeded(context,module);
    assert(!loaded.val2);
    parsedModules.add(loaded.val1);
  }
  for (  ParsedModule module : parsedModules) {
    varAnalyzer.walkTopLevel(context,module);
  }
  backend.startFunction(FnID.ENTRY_FUNCTION,Var.NONE,Var.NONE,ExecTarget.syncControl());
  for (int i=0; i < parsedModules.size(); i++) {
    walkFile(context,topLevelContext,locatedModules.get(i),parsedModules.get(i),FrontendPass.COMPILE_TOPLEVEL);
  }
  List<FnOverload> mainOverloads=context.lookupFunction(Constants.MAIN_FUNCTION);
  if (mainOverloads.size() == 1) {
    FnID mainID=mainOverloads.get(0).id;
    backend.functionCall(mainID,Arg.NONE,Var.NONE,ExecTarget.syncControl(),new TaskProps());
  }
 else   if (mainOverloads.size() >= 2) {
    throw new DoubleDefineException(context,"String_Node_Str" + Constants.MAIN_FUNCTION);
  }
  backend.endFunction();
}
Program: 132534
Project: 132534
Buggy source:
private void walkTopLevel(GlobalContext context,LocalContext topLevelContext,SwiftAST fileTree,FrontendPass pass) throws UserException {
  if (pass == FrontendPass.DEFINITIONS) {
    walkTopLevelDefs(context,fileTree);
  }
 else   if (pass == FrontendPass.COMPILE_TOPLEVEL) {
    walkTopLevelCompileStatements(topLevelContext,fileTree);
  }
 else {
    assert(pass == FrontendPass.COMPILE_FUNCTIONS);
    walkTopLevelCompileFunctions(context,fileTree);
  }
}

Fixed version (ground truth):
private void walkTopLevel(GlobalContext context,LocalContext topLevelContext,ParsedModule module,FrontendPass pass) throws UserException {
  if (pass == FrontendPass.DEFINITIONS) {
    walkTopLevelDefs(context,module);
  }
 else   if (pass == FrontendPass.COMPILE_TOPLEVEL) {
    walkTopLevelCompileStatements(topLevelContext,module);
  }
 else {
    assert(pass == FrontendPass.COMPILE_FUNCTIONS);
    walkTopLevelCompileFunctions(context,module);
  }
}
Program: 132535
Project: 132535
Buggy source:
/** 
 * Second pass: - Compile top-level statements
 * @param globalContext
 * @param fileTree
 * @throws UserException
 */
private void walkTopLevelCompileStatements(LocalContext context,SwiftAST fileTree) throws UserException {
  assert(fileTree.getType() == ExMParser.PROGRAM);
  syncFilePos(context,fileTree);
  List<SwiftAST> stmts=new ArrayList<SwiftAST>();
  for (  SwiftAST stmt : fileTree.children()) {
    syncFilePos(context,stmt);
    int type=stmt.getType();
    if (TopLevel.isStatement(type)) {
      stmts.add(stmt);
    }
 else     if (type == ExMParser.IMPORT) {
      importModule(context.getGlobals(),context,stmt,FrontendPass.COMPILE_TOPLEVEL);
    }
 else     if (!TopLevel.isDefinition(type)) {
      throw new STCRuntimeError("String_Node_Str" + LogHelper.tokName(type) + "String_Node_Str");
    }
  }
  for (  SwiftAST stmt : stmts) {
    walkStatement(context,stmt,WalkMode.NORMAL);
  }
}

Fixed version (ground truth):
/** 
 * Second pass: - Compile top-level statements
 * @param context
 * @param module
 * @throws UserException
 */
private void walkTopLevelCompileStatements(LocalContext context,ParsedModule module) throws UserException {
  assert(module.ast.getType() == ExMParser.PROGRAM);
  if (!modules.needToCompileTopLevel(module)) {
    return;
  }
  syncFilePos(context,module.ast);
  List<SwiftAST> stmts=new ArrayList<SwiftAST>();
  for (  SwiftAST stmt : module.ast.children()) {
    syncFilePos(context,stmt);
    int type=stmt.getType();
    if (TopLevel.isStatement(type)) {
      stmts.add(stmt);
    }
 else     if (type == ExMParser.IMPORT) {
      importModule(context.getGlobals(),context,stmt,FrontendPass.COMPILE_TOPLEVEL);
    }
 else     if (!TopLevel.isDefinition(type)) {
      throw new STCRuntimeError("String_Node_Str" + LogHelper.tokName(type) + "String_Node_Str");
    }
  }
  for (  SwiftAST stmt : stmts) {
    walkStatement(context,stmt,WalkMode.NORMAL);
  }
}
Program: 132536
Project: 132536
Buggy source:
/** 
 * First pass: - Register (but don't compile) all functions and other definitions
 * @param context
 * @param fileTree
 * @throws UserException
 * @throws DoubleDefineException
 * @throws UndefinedTypeException
 */
private void walkTopLevelDefs(GlobalContext context,SwiftAST fileTree) throws UserException {
  assert(fileTree.getType() == ExMParser.PROGRAM);
  syncFilePos(context,fileTree);
  for (  SwiftAST stmt : fileTree.children()) {
    int type=stmt.getType();
    syncFilePos(context,stmt);
switch (type) {
case ExMParser.IMPORT:
      importModule(context,null,stmt,FrontendPass.DEFINITIONS);
    break;
case ExMParser.DEFINE_BUILTIN_FUNCTION:
  defineBuiltinFunction(context,stmt);
break;
case ExMParser.DEFINE_FUNCTION:
defineFunction(context,stmt);
break;
case ExMParser.DEFINE_APP_FUNCTION:
defineAppFunction(context,stmt);
break;
case ExMParser.DEFINE_NEW_STRUCT_TYPE:
defineNewStructType(context,stmt);
break;
case ExMParser.DEFINE_NEW_TYPE:
case ExMParser.TYPEDEF:
defineNewType(context,stmt,type == ExMParser.TYPEDEF);
break;
case ExMParser.GLOBAL_CONST:
globalConst(context,stmt);
break;
case ExMParser.PRAGMA:
pragmaTopLevel(context,stmt);
break;
case ExMParser.EOF:
break;
default :
if (!TopLevel.isStatement(type)) {
throw new STCRuntimeError("String_Node_Str" + LogHelper.tokName(type) + "String_Node_Str");
}
}
}
}

Fixed version (ground truth):
/** 
 * First pass: - Register (but don't compile) all functions and other definitions
 * @param context
 * @param module
 * @throws UserException
 * @throws DoubleDefineException
 * @throws UndefinedTypeException
 */
private void walkTopLevelDefs(GlobalContext context,ParsedModule module) throws UserException {
  assert(module.ast.getType() == ExMParser.PROGRAM);
  syncFilePos(context,module.ast);
  for (  SwiftAST stmt : module.ast.children()) {
    int type=stmt.getType();
    syncFilePos(context,stmt);
switch (type) {
case ExMParser.IMPORT:
      importModule(context,null,stmt,FrontendPass.DEFINITIONS);
    break;
case ExMParser.DEFINE_BUILTIN_FUNCTION:
  defineBuiltinFunction(context,stmt);
break;
case ExMParser.DEFINE_FUNCTION:
defineFunction(context,stmt);
break;
case ExMParser.DEFINE_APP_FUNCTION:
defineAppFunction(context,stmt);
break;
case ExMParser.DEFINE_NEW_STRUCT_TYPE:
defineNewStructType(context,stmt);
break;
case ExMParser.DEFINE_NEW_TYPE:
case ExMParser.TYPEDEF:
defineNewType(context,stmt,type == ExMParser.TYPEDEF);
break;
case ExMParser.GLOBAL_CONST:
globalConst(context,stmt);
break;
case ExMParser.PRAGMA:
pragmaTopLevel(context,stmt);
break;
case ExMParser.EOF:
break;
default :
if (!TopLevel.isStatement(type)) {
throw new STCRuntimeError("String_Node_Str" + LogHelper.tokName(type) + "String_Node_Str");
}
}
}
}
Program: 132537
Project: 132537
Buggy source:
/** 
 * Walk the statements in a file.
 * @param context
 * @param topLevelContext required for some passes
 * @param module the parsed file to compile
 * @param pass controls whether we just load top-level defs, or whetherwe attempt to compile the module
 * @throws UserException
 */
private void walkFile(GlobalContext context,LocalContext topLevelContext,LocatedModule module,ParsedModule parsed,FrontendPass pass) throws UserException {
  LogHelper.debug(context,"String_Node_Str" + module.canonicalName + "String_Node_Str"+ pass);
  modules.enterModule(module,parsed);
  walkTopLevel(context,topLevelContext,parsed.ast,pass);
  modules.exitModule();
  LogHelper.debug(context,"String_Node_Str" + module.canonicalName + "String_Node_Str"+ pass);
}

Fixed version (ground truth):
/** 
 * Walk the statements in a file.
 * @param context
 * @param topLevelContext required for some passes
 * @param module the parsed file to compile
 * @param pass controls whether we just load top-level defs, or whetherwe attempt to compile the module
 * @throws UserException
 */
private void walkFile(GlobalContext context,LocalContext topLevelContext,LocatedModule module,ParsedModule parsed,FrontendPass pass) throws UserException {
  LogHelper.debug(context,"String_Node_Str" + module.canonicalName + "String_Node_Str"+ pass);
  modules.enterModule(module,parsed);
  walkTopLevel(context,topLevelContext,parsed,pass);
  modules.exitModule();
  LogHelper.debug(context,"String_Node_Str" + module.canonicalName + "String_Node_Str"+ pass);
}
Program: 132538
Project: 132538
Buggy source:
/** 
 * Third pass: - Compile composite and app functions, now that all function names and globals are known
 * @param context
 * @param fileTree
 * @throws UserException
 */
private void walkTopLevelCompileFunctions(GlobalContext context,SwiftAST fileTree) throws UserException {
  assert(fileTree.getType() == ExMParser.PROGRAM);
  syncFilePos(context,fileTree);
  for (  SwiftAST stmt : fileTree.children()) {
    syncFilePos(context,stmt);
    int type=stmt.getType();
    if (type == ExMParser.DEFINE_FUNCTION) {
      compileFunction(context,stmt);
    }
 else     if (type == ExMParser.DEFINE_APP_FUNCTION) {
      compileAppFunction(context,stmt);
    }
 else     if (TopLevel.isStatement(type) || TopLevel.isDefinition(type)) {
    }
 else {
      throw new STCRuntimeError("String_Node_Str" + LogHelper.tokName(type) + "String_Node_Str");
    }
  }
}

Fixed version (ground truth):
/** 
 * Third pass: - Compile composite and app functions, now that all function names and globals are known
 * @param context
 * @param fileTree
 * @throws UserException
 */
private void walkTopLevelCompileFunctions(GlobalContext context,ParsedModule module) throws UserException {
  assert(module.ast.getType() == ExMParser.PROGRAM);
  syncFilePos(context,module.ast);
  for (  SwiftAST stmt : module.ast.children()) {
    syncFilePos(context,stmt);
    int type=stmt.getType();
    if (type == ExMParser.DEFINE_FUNCTION) {
      compileFunction(context,stmt);
    }
 else     if (type == ExMParser.DEFINE_APP_FUNCTION) {
      compileAppFunction(context,stmt);
    }
 else     if (TopLevel.isStatement(type) || TopLevel.isDefinition(type)) {
    }
 else {
      throw new STCRuntimeError("String_Node_Str" + LogHelper.tokName(type) + "String_Node_Str");
    }
  }
}
Program: 132539
Project: 132539
Buggy source:
/** 
 * Walk the AST and make calls to backend to generate lower level code. This function is called to start the walk at the top level file
 * @param mainFilePath the main file path to process
 * @param originalMainFilePath original main file, in case a temporary fileis being directly parsed
 * @param preprocessed true if module was preprocessed
 * @throws UserException
 */
public void walk(String mainFilePath,String originalMainFilePath,boolean preprocessed) throws UserException {
  GlobalContext context=new GlobalContext(mainFilePath,Logging.getSTCLogger(),foreignFuncs);
  String mainModuleName=FilenameUtils.getBaseName(originalMainFilePath);
  LocatedModule mainModule=new LocatedModule(mainFilePath,mainModuleName,preprocessed);
  LocatedModule builtins=LocatedModule.fromPath(context,Arrays.asList("String_Node_Str"),false);
  loadDefinitions(context,mainModule,builtins);
  compileTopLevel(context,mainModule);
  compileFunctions(context);
}

Fixed version (ground truth):
/** 
 * Walk the AST and make calls to backend to generate lower level code. This function is called to start the walk at the top level file
 * @param mainFilePath the main file path to process
 * @param originalMainFilePath original main file, in case a temporary fileis being directly parsed
 * @param preprocessed true if module was preprocessed
 * @throws UserException
 */
public void walk(String mainFilePath,String originalMainFilePath,boolean preprocessed) throws UserException {
  GlobalContext context=new GlobalContext(mainFilePath,Logging.getSTCLogger(),foreignFuncs);
  String mainModuleName=FilenameUtils.getBaseName(originalMainFilePath);
  LocatedModule mainModule=new LocatedModule(mainFilePath,mainModuleName,preprocessed);
  LocatedModule builtins=LocatedModule.fromPath(context,Arrays.asList("String_Node_Str"),false);
  loadDefinitions(context,mainModule,builtins);
  compileTopLevel(context,mainModule,builtins);
  compileFunctions(context);
}
Program: 132540
Project: 132540
Buggy source:
private void assignExpression(Context context,VariableUsageInfo vu,SwiftAST tree) throws UserException {
  if (tree.getChildCount() < 2)   throw new STCRuntimeError("String_Node_Str");
  Assignment assignments=Assignment.fromAST(context,tree);
  for (  Pair<List<LValue>,SwiftAST> assign : assignments.getMatchedAssignments(context)) {
    List<LValue> lVals=assign.val1;
    SwiftAST rVal=assign.val2;
    Type rValT=TypeChecker.findExprType(context,lVals,rVal);
    List<Type> rValFields=TupleType.getFields(rValT);
    walkExpr(context,vu,rVal);
    Map<String,Type> rValTVBindings=new TreeMap<String,Type>();
    for (int i=0; i < lVals.size(); i++) {
      LValue lVal=lVals.get(i);
      syncFilePos(context,lVal.tree);
      if (lVal.var == null) {
        lVal=lVal.varDeclarationNeeded(context,rValFields.get(i));
        assert(lVal != null);
        vu.declare(context,lVal.var.name(),lVal.var.type(),false);
        context.declareVariable(lVal.var.type(),lVal.var.name(),Alloc.STACK,DefType.LOCAL_USER,VarProvenance.unknown(),false);
      }
 else {
        TypeChecker.checkAssignment(context,assignments.op,rValT,lVal.getType(context),lVal.toString(),rValTVBindings);
      }
      singleAssignment(context,vu,lVal,assignments.op);
    }
  }
}

Fixed version (ground truth):
private void assignExpression(Context context,VariableUsageInfo vu,SwiftAST tree) throws UserException {
  if (tree.getChildCount() < 2)   throw new STCRuntimeError("String_Node_Str");
  Assignment assignments=Assignment.fromAST(context,tree);
  for (  Pair<List<LValue>,SwiftAST> assign : assignments.getMatchedAssignments(context)) {
    List<LValue> lVals=assign.val1;
    SwiftAST rVal=assign.val2;
    Type rValT=TypeChecker.findExprType(context,lVals,rVal);
    List<Type> rValFields=TupleType.getFields(rValT);
    walkExpr(context,vu,rVal);
    Map<String,Type> rValTVBindings=new TreeMap<String,Type>();
    for (int i=0; i < lVals.size(); i++) {
      LValue lVal=lVals.get(i);
      Type rValFieldType=rValFields.get(i);
      syncFilePos(context,lVal.tree);
      if (lVal.var == null) {
        lVal=lVal.varDeclarationNeeded(context,rValFieldType);
        assert(lVal != null);
        vu.declare(context,lVal.var.name(),lVal.var.type(),false);
        context.declareVariable(lVal.var.type(),lVal.var.name(),Alloc.STACK,DefType.LOCAL_USER,VarProvenance.unknown(),false);
      }
 else {
        TypeChecker.checkAssignment(context,assignments.op,rValFieldType,lVal.getType(context),lVal.toString(),rValTVBindings);
      }
      singleAssignment(context,vu,lVal,assignments.op);
    }
  }
}
Program: 132543
Project: 132543
Buggy source:
/** 
 * Overload resolution test with some matching args
 * @throws TypeMismatchException
 */
@Test public void testSelectOverloadPartialMatch() throws TypeMismatchException {
  FunctionType stringFn=makeSimpleFT(Types.F_INT,Types.F_FILE,Types.F_STRING);
  FunctionType blobFn=makeSimpleFT(Types.F_INT,Types.F_FILE,Types.F_BLOB);
  FnID blobFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID stringFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_INT,Types.F_FILE,Types.F_STRING),Arrays.asList(Pair.create(blobFnID,blobFn),Pair.create(stringFnID,stringFn)));
  List<FnMatch> matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assert(matches.size() == 0);
  FnMatch match=matches.get(0);
  assert(match.id.equals(stringFnID));
  assert(match.concreteAlts.size() == 1);
  assert(match.concreteAlts.get(0).equals(stringFn));
}

Fixed version (ground truth):
/** 
 * Overload resolution test with some matching args
 * @throws TypeMismatchException
 */
@Test public void testSelectOverloadPartialMatch() throws TypeMismatchException {
  FunctionType stringFn=makeSimpleFT(Types.F_INT,Types.F_FILE,Types.F_STRING);
  FunctionType blobFn=makeSimpleFT(Types.F_INT,Types.F_FILE,Types.F_BLOB);
  FnID blobFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID stringFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_INT,Types.F_FILE,Types.F_STRING),Arrays.asList(Pair.create(blobFnID,blobFn),Pair.create(stringFnID,stringFn)));
  List<FnMatch> matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assertEquals(1,matches.size());
  FnMatch match=matches.get(0);
  assertEquals(stringFnID,match.id);
  assertEquals(1,match.concreteAlts.size());
  assertEquals(stringFn,match.concreteAlts.get(0));
}
Program: 132544
Project: 132544
Buggy source:
/** 
 * Check that union args are handled correctly when resolving overloads
 * @throws TypeMismatchException
 */
@Test public void testSelectOverloadUnion1() throws TypeMismatchException {
  FunctionType intFn=makeSimpleFT(Types.F_INT);
  FunctionType floatFn=makeSimpleFT(Types.F_FLOAT);
  FnID intFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID floatFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(INT_OR_STRING),Arrays.asList(Pair.create(intFnID,intFn),Pair.create(floatFnID,floatFn)));
  List<FnMatch> matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assert(matches.size() == 0);
  FnMatch match=matches.get(0);
  assert(match.id.equals(intFnID));
  assert(match.concreteAlts.size() == 1);
  assert(match.concreteAlts.get(0).equals(intFn));
}

Fixed version (ground truth):
/** 
 * Check that union args are handled correctly when resolving overloads
 * @throws TypeMismatchException
 */
@Test public void testSelectOverloadUnion1() throws TypeMismatchException {
  FunctionType intFn=makeSimpleFT(Types.F_INT);
  FunctionType floatFn=makeSimpleFT(Types.F_FLOAT);
  FnID intFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID floatFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(INT_OR_STRING),Arrays.asList(Pair.create(intFnID,intFn),Pair.create(floatFnID,floatFn)));
  List<FnMatch> matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assertEquals(1,matches.size());
  FnMatch match=matches.get(0);
  assertEquals(intFnID,match.id);
  assertEquals(1,match.concreteAlts.size());
  assertEquals(intFn,match.concreteAlts.get(0));
}
Program: 132546
Project: 132546
Buggy source:
/** 
 * Simple overload resolution test
 * @throws TypeMismatchException
 */
@Test public void testSelectOverload() throws TypeMismatchException {
  FunctionType intFn=makeSimpleFT(Types.F_INT);
  FunctionType stringFn=makeSimpleFT(Types.F_STRING);
  FnID intFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID stringFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_STRING),Arrays.asList(Pair.create(intFnID,intFn),Pair.create(stringFnID,stringFn)));
  List<FnMatch> matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assert(matches.size() == 0);
  FnMatch match=matches.get(0);
  assert(match.id.equals(stringFnID));
  assert(match.concreteAlts.size() == 1);
  assert(match.concreteAlts.get(0).equals(stringFn));
}

Fixed version (ground truth):
/** 
 * Simple overload resolution test
 * @throws TypeMismatchException
 */
@Test public void testSelectOverload() throws TypeMismatchException {
  FunctionType intFn=makeSimpleFT(Types.F_INT);
  FunctionType stringFn=makeSimpleFT(Types.F_STRING);
  FnID intFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID stringFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_STRING),Arrays.asList(Pair.create(intFnID,intFn),Pair.create(stringFnID,stringFn)));
  List<FnMatch> matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assertEquals(1,matches.size());
  FnMatch match=matches.get(0);
  assertEquals(stringFnID,match.id);
  assertEquals(1,match.concreteAlts.size());
  assertEquals(stringFn,match.concreteAlts.get(0));
}
Program: 132548
Project: 132548
Buggy source:
/** 
 * Helper to choose variable name.
 * @param prefix Prefix that must be at start
 * @param preferredSuffix Preferred suffix
 * @param counterName name of counter to use to make unique if needed
 * @return
 */
protected String uniqueName(String prefix,String preferredSuffix,String counterName){
  if (preferredSuffix != null) {
    prefix+=preferredSuffix;
    if (lookupDef(prefix) == null) {
      return prefix;
    }
  }
  String name=null;
  do {
    long counter=nextCounterVal(counterName);
    name=prefix + counter;
  }
 while (lookupDef(name) != null);
  return name;
}

Fixed version (ground truth):
/** 
 * Helper to choose variable name.
 * @param prefix Prefix that must be at start
 * @param preferredSuffix Preferred suffix
 * @param counterName name of counter to use to make unique if needed
 * @return
 */
protected String uniqueName(String prefix,String preferredSuffix,String counterName){
  if (preferredSuffix != null) {
    prefix+=preferredSuffix;
  }
  if (lookupDef(prefix) == null) {
    return prefix;
  }
  String name=null;
  do {
    long counter=nextCounterVal(counterName);
    name=prefix + counter;
  }
 while (lookupDef(name) != null);
  return name;
}
Program: 132549
Project: 132549
Buggy source:
@Override public FnID defineFunction(String name,FunctionType type,DefaultVals<Var> defaultVals) throws UserException {
  DefInfo def=lookupDef(name);
  if (def != null && def.kind == DefKind.FUNCTION) {
    return overloadFunction(name,type,defaultVals);
  }
 else {
    declareVariable(type,name,Alloc.GLOBAL_CONST,DefType.GLOBAL_CONST,VarProvenance.userVar(getSourceLoc()),false);
    FnID fnID=new FnID(name,name);
    addFunctionOverload(name,fnID,type,defaultVals);
    return fnID;
  }
}

Fixed version (ground truth):
@Override public FnID defineFunction(String name,FunctionType type,DefaultVals<Var> defaultVals) throws UserException {
  FnID fnID;
  DefInfo def=lookupDef(name);
  if (def != null && def.kind == DefKind.FUNCTION) {
    fnID=overloadFunction(name,type,defaultVals);
    declareVariable(type,fnID.uniqueName(),Alloc.GLOBAL_CONST,DefType.GLOBAL_CONST,VarProvenance.userVar(getSourceLoc()),false);
  }
 else {
    declareVariable(type,name,Alloc.GLOBAL_CONST,DefType.GLOBAL_CONST,VarProvenance.userVar(getSourceLoc()),false);
    fnID=new FnID(name,name);
    addFunctionOverload(name,fnID,type,defaultVals);
  }
  return fnID;
}
Program: 132550
Project: 132550
Buggy source:
private static void noMatchingOverloadsException(Context context,FnCallInfo fc) throws TypeMismatchException {
  StringBuilder sb=new StringBuilder();
  sb.append("String_Node_Str");
  sb.append(typeList(fc.argTypes));
  sb.append("String_Node_Str" + fc.name + "String_Node_Str");
  sb.append("String_Node_Str");
  for (  FnOverload fnType : fc.fnTypes) {
    sb.append(typeList(fnType.type.getInputs()));
    sb.append('\n');
  }
  throw new TypeMismatchException(context,sb.toString());
}

Fixed version (ground truth):
private static TypeMismatchException noMatchingOverloadsException(Context context,FnCallInfo fc){
  StringBuilder sb=new StringBuilder();
  sb.append("String_Node_Str");
  sb.append(typeList(fc.argTypes));
  sb.append("String_Node_Str" + fc.name + "String_Node_Str");
  sb.append("String_Node_Str");
  for (  FnOverload fnType : fc.fnTypes) {
    sb.append(typeList(fnType.type.getInputs()));
    sb.append('\n');
  }
  return new TypeMismatchException(context,sb.toString());
}
Program: 132551
Project: 132551
Buggy source:
public static ConcreteMatch concretiseFunctionCall(Context context,FunctionCall fc,List<Var> outputs) throws UserException {
}

Fixed version (ground truth):
public static ConcreteMatch concretiseFunctionCall(Context context,FunctionCall fc,List<Var> outputs) throws UserException {
  FnMatch match=concretiseInputs(context,fc);
  List<Type> outTs=Var.extractTypes(outputs);
  FunctionType concreteOutTs=concretiseOutputs(context,match,outputs,outTs);
  return new ConcreteMatch(match.overload.id,concreteOutTs,match.overload.defaultVals);
}
Program: 132552
Project: 132552
Buggy source:
/** 
 * Narrow possible function call types based on inputs.
 * @param context
 * @param fc
 * @param resolveOverload if true, resolve to a single overload
 * @return list of possible concrete function types with varargs, typevarsand union type args removed.  Grouped by which overload they match.  Each match should have at least one concrete function type associated with it.
 * @throws UserException
 */
private static List<FnMatch> concretiseInputs(Context context,FunctionCall fc,boolean resolveOverload) throws UserException {
  List<Type> argTypes=new ArrayList<Type>(fc.args().size());
  for (  SwiftAST arg : fc.args()) {
    argTypes.add(TypeChecker.findExprType(context,arg));
  }
  FnCallInfo info=new FnCallInfo(fc.originalName(),fc.overloads(),argTypes);
  return concretiseInputsOverloaded(context,info,resolveOverload);
}

Fixed version (ground truth):
/** 
 * Narrow possible function call types based on inputs.
 * @param context
 * @param fc
 * @param resolveOverload if true, resolve to a single overload
 * @return list of possible concrete function types with varargs, typevarsand union type args removed.  Grouped by which overload they match.  Each match should have at least one concrete function type associated with it.
 * @throws UserException
 */
private static FnMatch concretiseInputs(Context context,FunctionCall fc) throws UserException {
  List<Type> argTypes=new ArrayList<Type>(fc.args().size());
  for (  SwiftAST arg : fc.args()) {
    argTypes.add(TypeChecker.findExprType(context,arg));
  }
  FnCallInfo info=new FnCallInfo(fc.originalName(),fc.overloads(),argTypes);
  return concretiseInputsOverloaded(context,info);
}
Program: 132553
Project: 132553
Buggy source:
static List<FnMatch> concretiseInputsOverloaded(Context context,FnCallInfo fc,boolean resolveOverload) throws TypeMismatchException {
}

Fixed version (ground truth):
/** 
 * Resolve overloaded function call to a single overload based on input arguments (output arguments are *not* used to resolve overloads).
 * @param context
 * @param fc
 * @return
 * @throws TypeMismatchException
 */
static FnMatch concretiseInputsOverloaded(Context context,FnCallInfo fc) throws TypeMismatchException {
}
Program: 132554
Project: 132554
Buggy source:
public static Type findFuncCallExprType(Context context,SwiftAST tree) throws UndefinedFunctionException, UserException {
  FunctionCall f=FunctionCall.fromAST(context,tree,false);
  return exprTypeFromMatches(concretiseInputs(context,f,false));
}

Fixed version (ground truth):
public static Type findFuncCallExprType(Context context,SwiftAST tree) throws UndefinedFunctionException, UserException {
  FunctionCall f=FunctionCall.fromAST(context,tree,false);
  return exprTypeFromMatch(concretiseInputs(context,f));
}
Program: 132555
Project: 132555
Buggy source:
@Test public void testSelectOverloadNoMatch2() throws TypeMismatchException {
  exception.expect(TypeMismatchException.class);
  FunctionType intFn=makeSimpleFT(Types.F_INT);
  FunctionType stringFn=makeSimpleFT(Types.F_STRING);
  FnID intFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID stringFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_FLOAT,Types.F_FLOAT),Arrays.asList(new FnOverload(intFnID,intFn),new FnOverload(stringFnID,stringFn)));
  concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
}

Fixed version (ground truth):
@Test public void testSelectOverloadNoMatch2() throws TypeMismatchException {
  exception.expect(TypeMismatchException.class);
  FunctionType intFn=makeSimpleFT(Types.F_INT);
  FunctionType stringFn=makeSimpleFT(Types.F_STRING);
  FnID intFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID stringFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_FLOAT,Types.F_FLOAT),Arrays.asList(new FnOverload(intFnID,intFn),new FnOverload(stringFnID,stringFn)));
  concretiseInputsOverloaded(FAKE_CONTEXT,fc);
}
Program: 132556
Project: 132556
Buggy source:
/** 
 * Overload resolution test with some matching args
 * @throws TypeMismatchException
 */
@Test public void testSelectOverloadPartialMatch() throws TypeMismatchException {
  FunctionType stringFn=makeSimpleFT(Types.F_INT,Types.F_FILE,Types.F_STRING);
  FunctionType blobFn=makeSimpleFT(Types.F_INT,Types.F_FILE,Types.F_BLOB);
  FnID blobFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID stringFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_INT,Types.F_FILE,Types.F_STRING),Arrays.asList(new FnOverload(blobFnID,blobFn),new FnOverload(stringFnID,stringFn)));
  List<FnMatch> matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assertEquals(1,matches.size());
  FnMatch match=matches.get(0);
  assertEquals(stringFnID,match.overload.id);
  assertEquals(1,match.concreteAlts.size());
  assertEquals(stringFn,match.concreteAlts.get(0));
}

Fixed version (ground truth):
/** 
 * Overload resolution test with some matching args
 * @throws TypeMismatchException
 */
@Test public void testSelectOverloadPartialMatch() throws TypeMismatchException {
  FunctionType stringFn=makeSimpleFT(Types.F_INT,Types.F_FILE,Types.F_STRING);
  FunctionType blobFn=makeSimpleFT(Types.F_INT,Types.F_FILE,Types.F_BLOB);
  FnID blobFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID stringFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_INT,Types.F_FILE,Types.F_STRING),Arrays.asList(new FnOverload(blobFnID,blobFn),new FnOverload(stringFnID,stringFn)));
  FnMatch match=concretiseInputsOverloaded(FAKE_CONTEXT,fc);
  assertEquals(stringFnID,match.overload.id);
  assertEquals(1,match.concreteAlts.size());
  assertEquals(stringFn,match.concreteAlts.get(0));
}
Program: 132557
Project: 132557
Buggy source:
@Test public void testMatchOptional() throws TypeMismatchException {
  String name="String_Node_Str";
  FunctionType ft=makeSimpleFT(Types.F_INT,Types.F_BOOL);
  Var constVar=new Var(Types.F_BOOL,"String_Node_Str",Alloc.GLOBAL_CONST,DefType.GLOBAL_CONST,VarProvenance.unknown());
  DefaultVals<Var> defaults=DefaultVals.fromDefaultValVector(Arrays.asList(null,constVar));
  FnOverload fo=new FnOverload(new FnID(name,name),ft,defaults);
  FnCallInfo fc;
  List<FnMatch> matches;
  FnMatch match;
  List<Type> intBoolArgs=Arrays.asList(Types.F_INT,Types.F_BOOL);
  fc=new FnCallInfo(name,fo.asList(),intBoolArgs);
  matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assertEquals("String_Node_Str",1,matches.size());
  match=matches.get(0);
  assertEquals("String_Node_Str",1,match.concreteAlts.size());
  assertEquals("String_Node_Str",intBoolArgs,match.concreteAlts.get(0).getInputs());
  List<Type> intArgs=Arrays.asList(Types.F_INT);
  fc=new FnCallInfo(name,fo.asList(),intArgs);
  matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assertEquals("String_Node_Str",1,matches.size());
  match=matches.get(0);
  assertEquals("String_Node_Str",1,match.concreteAlts.size());
  assertEquals("String_Node_Str",intArgs,match.concreteAlts.get(0).getInputs());
}

Fixed version (ground truth):
@Test public void testMatchOptional() throws TypeMismatchException {
  String name="String_Node_Str";
  FunctionType ft=makeSimpleFT(Types.F_INT,Types.F_BOOL);
  Var constVar=new Var(Types.F_BOOL,"String_Node_Str",Alloc.GLOBAL_CONST,DefType.GLOBAL_CONST,VarProvenance.unknown());
  DefaultVals<Var> defaults=DefaultVals.fromDefaultValVector(Arrays.asList(null,constVar));
  FnOverload fo=new FnOverload(new FnID(name,name),ft,defaults);
  List<Type> intBoolArgs=Arrays.asList(Types.F_INT,Types.F_BOOL);
  FnCallInfo fc=new FnCallInfo(name,fo.asList(),intBoolArgs);
  FnMatch match=concretiseInputsOverloaded(FAKE_CONTEXT,fc);
  assertEquals("String_Node_Str",1,match.concreteAlts.size());
  assertEquals("String_Node_Str",intBoolArgs,match.concreteAlts.get(0).getInputs());
  List<Type> intArgs=Arrays.asList(Types.F_INT);
  fc=new FnCallInfo(name,fo.asList(),intArgs);
  match=concretiseInputsOverloaded(FAKE_CONTEXT,fc);
  assertEquals("String_Node_Str",1,match.concreteAlts.size());
  assertEquals("String_Node_Str",intArgs,match.concreteAlts.get(0).getInputs());
}
Program: 132558
Project: 132558
Buggy source:
/** 
 * Check that union args are handled correctly when resolving overloads
 * @throws TypeMismatchException
 */
@Test public void testSelectOverloadUnion1() throws TypeMismatchException {
  FunctionType intFn=makeSimpleFT(Types.F_INT);
  FunctionType floatFn=makeSimpleFT(Types.F_FLOAT);
  FnID intFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID floatFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(INT_OR_STRING),Arrays.asList(new FnOverload(intFnID,intFn),new FnOverload(floatFnID,floatFn)));
  List<FnMatch> matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assertEquals(1,matches.size());
  FnMatch match=matches.get(0);
  assertEquals(intFnID,match.overload.id);
  assertEquals(1,match.concreteAlts.size());
  assertEquals(intFn,match.concreteAlts.get(0));
}

Fixed version (ground truth):
/** 
 * Check that union args are handled correctly when resolving overloads
 * @throws TypeMismatchException
 */
@Test public void testSelectOverloadUnion1() throws TypeMismatchException {
  FunctionType intFn=makeSimpleFT(Types.F_INT);
  FunctionType floatFn=makeSimpleFT(Types.F_FLOAT);
  FnID intFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID floatFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(INT_OR_STRING),Arrays.asList(new FnOverload(intFnID,intFn),new FnOverload(floatFnID,floatFn)));
  FnMatch match=concretiseInputsOverloaded(FAKE_CONTEXT,fc);
  assertEquals(intFnID,match.overload.id);
  assertEquals(1,match.concreteAlts.size());
  assertEquals(intFn,match.concreteAlts.get(0));
}
Program: 132560
Project: 132560
Buggy source:
@Test public void testSelectOverloadVarArgs1() throws TypeMismatchException {
  FunctionType ft1=makeFT(Arrays.asList(Types.F_STRING,Types.F_STRING),true);
  FunctionType ft2=makeFT(Arrays.asList(FLOAT_OR_INT),true);
  FnID fid1=new FnID("String_Node_Str","String_Node_Str");
  FnID fid2=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_STRING,Types.F_STRING),Arrays.asList(new FnOverload(fid1,ft1),new FnOverload(fid2,ft2)));
  List<FnMatch> matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assert(matches.size() == 0);
  FnMatch match=matches.get(0);
  assert(match.overload.id.equals(fid1));
  assert(match.concreteAlts.size() == 1);
  assert(match.concreteAlts.get(0).equals(ft1));
}

Fixed version (ground truth):
@Test public void testSelectOverloadVarArgs1() throws TypeMismatchException {
  List<Type> twoStrings=Arrays.asList(Types.F_STRING,Types.F_STRING);
  FunctionType ft1=makeFT(twoStrings,true);
  FunctionType ft1NoVarArgs=makeFT(twoStrings,false);
  FunctionType ft2=makeFT(Arrays.asList(FLOAT_OR_INT),true);
  FnID fid1=new FnID("String_Node_Str","String_Node_Str");
  FnID fid2=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(twoStrings,Arrays.asList(new FnOverload(fid1,ft1),new FnOverload(fid2,ft2)));
  FnMatch match=concretiseInputsOverloaded(FAKE_CONTEXT,fc);
  assertEquals(fid1,match.overload.id);
  assertEquals(1,match.concreteAlts.size());
  assertEquals(ft1NoVarArgs,match.concreteAlts.get(0));
}
Program: 132561
Project: 132561
Buggy source:
@Test public void testMatchNoVarArgs() throws TypeMismatchException {
  FnCallInfo fc=makeFnCallInfo(VARARGS_TYPE,Arrays.asList(Types.F_INT,Types.F_FLOAT,Types.F_INT,Types.F_FLOAT));
  List<FnMatch> matches;
  matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,false);
  assertEquals("String_Node_Str",1,matches.size());
  FnMatch match=matches.get(0);
  assertEquals("String_Node_Str",1,match.concreteAlts.size());
  assertEquals("String_Node_Str",Arrays.asList(Types.F_INT,Types.F_FLOAT,Types.F_INT,Types.F_FLOAT),match.concreteAlts.get(0).getInputs());
}

Fixed version (ground truth):
@Test public void testMatchNoVarArgs() throws TypeMismatchException {
  FnCallInfo fc=makeFnCallInfo(VARARGS_TYPE,Arrays.asList(Types.F_INT,Types.F_FLOAT,Types.F_INT,Types.F_FLOAT));
  FnMatch match=concretiseInputsOverloaded(FAKE_CONTEXT,fc);
  assertEquals("String_Node_Str",1,match.concreteAlts.size());
  assertEquals("String_Node_Str",Arrays.asList(Types.F_INT,Types.F_FLOAT,Types.F_INT,Types.F_FLOAT),match.concreteAlts.get(0).getInputs());
}
Program: 132562
Project: 132562
Buggy source:
@Test public void testSelectOverloadNoMatch() throws TypeMismatchException {
  exception.expect(TypeMismatchException.class);
  FunctionType intFn=makeSimpleFT(Types.F_INT);
  FunctionType stringFn=makeSimpleFT(Types.F_STRING);
  FnID intFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID stringFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_FLOAT),Arrays.asList(new FnOverload(intFnID,intFn),new FnOverload(stringFnID,stringFn)));
  concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
}

Fixed version (ground truth):
@Test public void testSelectOverloadNoMatch() throws TypeMismatchException {
  exception.expect(TypeMismatchException.class);
  FunctionType intFn=makeSimpleFT(Types.F_INT);
  FunctionType stringFn=makeSimpleFT(Types.F_STRING);
  FnID intFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID stringFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_FLOAT),Arrays.asList(new FnOverload(intFnID,intFn),new FnOverload(stringFnID,stringFn)));
  concretiseInputsOverloaded(FAKE_CONTEXT,fc);
}
Program: 132563
Project: 132563
Buggy source:
/** 
 * Simple overload resolution test
 * @throws TypeMismatchException
 */
@Test public void testSelectOverload() throws TypeMismatchException {
  FunctionType intFn=makeSimpleFT(Types.F_INT);
  FunctionType stringFn=makeSimpleFT(Types.F_STRING);
  FnID intFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID stringFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_STRING),Arrays.asList(new FnOverload(intFnID,intFn),new FnOverload(stringFnID,stringFn)));
  List<FnMatch> matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assertEquals(1,matches.size());
  FnMatch match=matches.get(0);
  assertEquals(stringFnID,match.overload.id);
  assertEquals(1,match.concreteAlts.size());
  assertEquals(stringFn,match.concreteAlts.get(0));
}

Fixed version (ground truth):
/** 
 * Simple overload resolution test
 * @throws TypeMismatchException
 */
@Test public void testSelectOverload() throws TypeMismatchException {
  FunctionType intFn=makeSimpleFT(Types.F_INT);
  FunctionType stringFn=makeSimpleFT(Types.F_STRING);
  FnID intFnID=new FnID("String_Node_Str","String_Node_Str");
  FnID stringFnID=new FnID("String_Node_Str","String_Node_Str");
  FnCallInfo fc=makeOverloadedFnCallInfo(Arrays.asList(Types.F_STRING),Arrays.asList(new FnOverload(intFnID,intFn),new FnOverload(stringFnID,stringFn)));
  FnMatch match=concretiseInputsOverloaded(FAKE_CONTEXT,fc);
  assertEquals(stringFnID,match.overload.id);
  assertEquals(1,match.concreteAlts.size());
  assertEquals(stringFn,match.concreteAlts.get(0));
}
Program: 132564
Project: 132564
Buggy source:
@Test public void testMatchMultiVarArgs() throws TypeMismatchException {
  FnCallInfo fc=makeFnCallInfo(VARARGS_TYPE,Arrays.asList(Types.F_INT));
  List<FnMatch> matches;
  matches=concretiseInputsOverloaded(FAKE_CONTEXT,fc,true);
  assertEquals("String_Node_Str",1,matches.size());
  FnMatch match=matches.get(0);
  assertEquals("String_Node_Str",1,match.concreteAlts.size());
  assertEquals("String_Node_Str",Arrays.asList(Types.F_INT),match.concreteAlts.get(0).getInputs());
}

Fixed version (ground truth):
@Test public void testMatchMultiVarArgs() throws TypeMismatchException {
  FnCallInfo fc=makeFnCallInfo(VARARGS_TYPE,Arrays.asList(Types.F_INT));
  FnMatch match=concretiseInputsOverloaded(FAKE_CONTEXT,fc);
  assertEquals("String_Node_Str",1,match.concreteAlts.size());
  assertEquals("String_Node_Str",Arrays.asList(Types.F_INT),match.concreteAlts.get(0).getInputs());
}
Program: 132565
Project: 132565
Buggy source:
@Test public void testMatchVarArgsFail() throws TypeMismatchException {
  exception.expect(TypeMismatchException.class);
  FnCallInfo fc=makeFnCallInfo(VARARGS_TYPE,Arrays.asList(Types.F_INT,Types.F_STRING));
  concretiseInputsOverloaded(FAKE_CONTEXT,fc,false);
}

Fixed version (ground truth):
@Test public void testMatchVarArgsFail() throws TypeMismatchException {
  exception.expect(TypeMismatchException.class);
  FnCallInfo fc=makeFnCallInfo(VARARGS_TYPE,Arrays.asList(Types.F_INT,Types.F_STRING));
  concretiseInputsOverloaded(FAKE_CONTEXT,fc);
}
Program: 132568
Project: 132568
Buggy source:
private void assignExpression(Context context,VariableUsageInfo vu,SwiftAST tree) throws UserException {
  if (tree.getChildCount() < 2)   throw new STCRuntimeError("String_Node_Str");
  Assignment assignments=Assignment.fromAST(context,tree);
  for (  Pair<List<LValue>,SwiftAST> assign : assignments.getMatchedAssignments(context)) {
    List<LValue> lVals=assign.val1;
    SwiftAST rVal=assign.val2;
    Type rValT=TypeChecker.findExprType(context,lVals,rVal);
    List<Type> rValFields=TupleType.getFields(rValT);
    walkExpr(context,vu,rVal);
    Map<String,Type> rValTVBindings=new TreeMap<String,Type>();
    for (int i=0; i < lVals.size(); i++) {
      LValue lVal=lVals.get(i);
      syncFilePos(context,lVal.tree);
      if (lVal.var == null) {
        lVal=lVal.varDeclarationNeeded(context,rValFields.get(i));
        assert(lVal != null);
        vu.declare(context,lVal.var.name(),lVal.var.type(),false);
        context.declareVariable(lVal.var.type(),lVal.var.name(),Alloc.STACK,DefType.LOCAL_USER,VarProvenance.unknown(),false);
      }
 else {
        TypeChecker.checkAssignment(context,assignments.op,rValT,lVal.getType(context),lVal.toString(),rValTVBindings);
      }
      singleAssignment(context,vu,lVal,assignments.op);
    }
  }
}

Fixed version (ground truth):
private void assignExpression(Context context,VariableUsageInfo vu,SwiftAST tree) throws UserException {
  if (tree.getChildCount() < 2)   throw new STCRuntimeError("String_Node_Str");
  Assignment assignments=Assignment.fromAST(context,tree);
  for (  Pair<List<LValue>,SwiftAST> assign : assignments.getMatchedAssignments(context)) {
    List<LValue> lVals=assign.val1;
    SwiftAST rVal=assign.val2;
    Type rValT=TypeChecker.findExprType(context,lVals,rVal);
    List<Type> rValFields=TupleType.getFields(rValT);
    walkExpr(context,vu,rVal);
    Map<String,Type> rValTVBindings=new TreeMap<String,Type>();
    for (int i=0; i < lVals.size(); i++) {
      LValue lVal=lVals.get(i);
      Type rValFieldType=rValFields.get(i);
      syncFilePos(context,lVal.tree);
      if (lVal.var == null) {
        lVal=lVal.varDeclarationNeeded(context,rValFieldType);
        assert(lVal != null);
        vu.declare(context,lVal.var.name(),lVal.var.type(),false);
        context.declareVariable(lVal.var.type(),lVal.var.name(),Alloc.STACK,DefType.LOCAL_USER,VarProvenance.unknown(),false);
      }
 else {
        TypeChecker.checkAssignment(context,assignments.op,rValFieldType,lVal.getType(context),lVal.toString(),rValTVBindings);
      }
      singleAssignment(context,vu,lVal,assignments.op);
    }
  }
}
Program: 132570
Project: 132570
Buggy source:
/** 
 * Switch to passing values directly. Do this before function inlining since function inlining will clean it up.
 * @param logger
 * @param program
 */
@Override public void optimize(Logger logger,Program program){
  Set<FnID> usedFunctionNames=program.getFunctionIDs();
  Map<FnID,Function> toInline=new HashMap<FnID,Function>();
  ListIterator<Function> fnIt=program.functionIterator();
  while (fnIt.hasNext()) {
    Function fn=fnIt.next();
    Function newFn=switchToValuePassing(logger,program.foreignFunctions(),fn,usedFunctionNames);
    if (newFn != null) {
      fnIt.remove();
      fnIt.add(newFn);
      usedFunctionNames.add(newFn.id());
      toInline.put(fn.id(),fn);
    }
  }
  FunctionInline.inlineAllOccurrences(logger,program,toInline);
}

Fixed version (ground truth):
/** 
 * Switch to passing values directly. Do this before function inlining since function inlining will clean it up.
 * @param logger
 * @param program
 */
@Override public void optimize(Logger logger,Program program){
  Set<FnID> usedFnIDs=new HashSet<FnID>(program.getFunctionMap().keySet());
  Map<FnID,Function> toInline=new HashMap<FnID,Function>();
  ListIterator<Function> fnIt=program.functionIterator();
  while (fnIt.hasNext()) {
    Function fn=fnIt.next();
    Function newFn=switchToValuePassing(logger,program.foreignFunctions(),fn,usedFnIDs);
    if (newFn != null) {
      fnIt.remove();
      fnIt.add(newFn);
      usedFnIDs.add(newFn.id());
      toInline.put(fn.id(),fn);
    }
  }
  FunctionInline.inlineAllOccurrences(logger,program,toInline);
}