nus-yam/ex-repair huggingface dataset:
Program: 132572
Project: 132572
Buggy source:
public void addUnifiedValues(GlobalConstants consts,String errContext,int stmtIndex,UnifiedValues unified) throws OptUnsafeError {
  int closedIndex=stmtIndex + 1;
  for (  Var closed : unified.closed) {
    markClosed(closed,closedIndex,false);
  }
  for (  Var closed : unified.recursivelyClosed) {
    markClosed(closed,closedIndex,true);
  }
  update(consts,errContext,unified.availableVals,null,stmtIndex);
}

Fixed version (ground truth):
public void addUnifiedValues(GlobalConstants consts,String errContext,int stmtIndex,UnifiedValues unified) throws OptUnsafeError {
  for (  Var closed : unified.closed) {
    markClosed(closed,stmtIndex,false);
  }
  for (  Var closed : unified.recursivelyClosed) {
    markClosed(closed,stmtIndex,true);
  }
  update(consts,errContext,unified.availableVals,null,stmtIndex);
}
Program: 132573
Project: 132573
Buggy source:
private void compileTopLevel(GlobalContext context,LocatedModule mainModule) throws UserException, UndefinedFunctionException, ModuleLoadException {
  Pair<ParsedModule,Boolean> loadedMainModule=modules.loadIfNeeded(context,mainModule);
  assert(!loadedMainModule.val2);
  varAnalyzer.walkTopLevel(context,loadedMainModule.val1.ast,moduleIterator(context));
  backend.startFunction(Constants.ENTRY_FUNCTION,Var.NONE,Var.NONE,ExecTarget.syncControl());
  for (  LocatedModule loadedModule : modules.loadedModules()) {
    loadModule(context,FrontendPass.COMPILE_TOPLEVEL,loadedModule);
  }
  FunctionType mainFn=context.lookupFunction(Constants.MAIN_FUNCTION);
  if (mainFn != null) {
    backend.functionCall(Constants.MAIN_FUNCTION,Constants.MAIN_FUNCTION,Arg.NONE,Var.NONE,ExecTarget.syncControl(),new TaskProps());
  }
  backend.endFunction();
}

Fixed version (ground truth):
private void compileTopLevel(GlobalContext context,LocalContext topLevelContext,LocatedModule mainModule) throws UserException, UndefinedFunctionException, ModuleLoadException {
  Pair<ParsedModule,Boolean> loadedMainModule=modules.loadIfNeeded(context,mainModule);
  assert(!loadedMainModule.val2);
  varAnalyzer.walkTopLevel(context,loadedMainModule.val1.ast,moduleIterator(context));
  backend.startFunction(Constants.ENTRY_FUNCTION,Var.NONE,Var.NONE,ExecTarget.syncControl());
  for (  LocatedModule loadedModule : modules.loadedModules()) {
    loadModule(context,topLevelContext,FrontendPass.COMPILE_TOPLEVEL,loadedModule);
  }
  FunctionType mainFn=context.lookupFunction(Constants.MAIN_FUNCTION);
  if (mainFn != null) {
    backend.functionCall(Constants.MAIN_FUNCTION,Constants.MAIN_FUNCTION,Arg.NONE,Var.NONE,ExecTarget.syncControl(),new TaskProps());
  }
  backend.endFunction();
}
Program: 132574
Project: 132574
Buggy source:
private void compileFunctions(GlobalContext context) throws ModuleLoadException, UserException {
  for (  LocatedModule loadedModule : modules.loadedModules()) {
    loadModule(context,FrontendPass.COMPILE_FUNCTIONS,loadedModule);
  }
}

Fixed version (ground truth):
private void compileFunctions(GlobalContext context,LocalContext topLevelContext) throws ModuleLoadException, UserException {
  for (  LocatedModule loadedModule : modules.loadedModules()) {
    loadModule(context,topLevelContext,FrontendPass.COMPILE_FUNCTIONS,loadedModule);
  }
}
Program: 132575
Project: 132575
Buggy source:
private void walkTopLevel(GlobalContext context,SwiftAST fileTree,FrontendPass pass) throws UserException {
  if (pass == FrontendPass.DEFINITIONS) {
    walkTopLevelDefs(context,fileTree);
  }
 else   if (pass == FrontendPass.COMPILE_TOPLEVEL) {
    walkTopLevelCompileStatements(context,fileTree);
  }
 else {
    assert(pass == FrontendPass.COMPILE_FUNCTIONS);
    walkTopLevelCompileFunctions(context,fileTree);
  }
}

Fixed version (ground truth):
private void walkTopLevel(GlobalContext context,LocalContext topLevelContext,SwiftAST fileTree,FrontendPass pass) throws UserException {
  if (pass == FrontendPass.DEFINITIONS) {
    walkTopLevelDefs(context,topLevelContext,fileTree);
  }
 else   if (pass == FrontendPass.COMPILE_TOPLEVEL) {
    walkTopLevelCompileStatements(topLevelContext,fileTree);
  }
 else {
    assert(pass == FrontendPass.COMPILE_FUNCTIONS);
    walkTopLevelCompileFunctions(context,fileTree);
  }
}
Program: 132576
Project: 132576
Buggy source:
/** 
 * Handle an import statement by loading definitions for, or compiling module as needed.
 * @param context
 * @param tree
 * @param pass
 * @throws UserException
 */
private void importModule(GlobalContext context,SwiftAST tree,FrontendPass pass) throws UserException {
  assert(tree.getType() == ExMParser.IMPORT);
  assert(tree.getChildCount() == 1);
  SwiftAST moduleID=tree.child(0);
  if (pass == FrontendPass.DEFINITIONS) {
    LocatedModule module=LocatedModule.fromModuleNameAST(context,moduleID,false);
    loadModule(context,pass,module);
  }
}

Fixed version (ground truth):
/** 
 * Handle an import statement by loading definitions for, or compiling module as needed.
 * @param context
 * @param tree
 * @param pass
 * @throws UserException
 */
private void importModule(GlobalContext context,LocalContext topLevelContext,SwiftAST tree,FrontendPass pass) throws UserException {
  assert(tree.getType() == ExMParser.IMPORT);
  assert(tree.getChildCount() == 1);
  SwiftAST moduleID=tree.child(0);
  if (pass == FrontendPass.DEFINITIONS) {
    LocatedModule module=LocatedModule.fromModuleNameAST(context,moduleID,false);
    loadModule(context,topLevelContext,pass,module);
  }
}
Program: 132577
Project: 132577
Buggy source:
/** 
 * Second pass: - Compile top-level statements
 * @param globalContext
 * @param fileTree
 * @throws UserException
 */
private void walkTopLevelCompileStatements(GlobalContext globalContext,SwiftAST fileTree) throws UserException {
  assert(fileTree.getType() == ExMParser.PROGRAM);
  Context context=LocalContext.topLevelContext(globalContext);
  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 (!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 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 (!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: 132578
Project: 132578
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, DoubleDefineException, UndefinedTypeException {
  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,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 fileTree
 * @throws UserException
 * @throws DoubleDefineException
 * @throws UndefinedTypeException
 */
private void walkTopLevelDefs(GlobalContext context,LocalContext topLevelContext,SwiftAST fileTree) throws UserException, DoubleDefineException, UndefinedTypeException {
  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,topLevelContext,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: 132579
Project: 132579
Buggy source:
/** 
 * Walk the statements in a file.
 * @param context
 * @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,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,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 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);
}
Program: 132580
Project: 132580
Buggy source:
/** 
 * Compile or load definitions for a module (depending on pass), if needed. Avoids double-compiling or double loading a module.
 * @param context
 * @param pass
 * @param module
 * @throws ModuleLoadException
 * @throws UserException
 */
private void loadModule(GlobalContext context,FrontendPass pass,LocatedModule module) throws ModuleLoadException, UserException {
  Pair<ParsedModule,Boolean> loaded=modules.loadIfNeeded(context,module);
  ParsedModule parsed=loaded.val1;
  boolean newlyLoaded=loaded.val2;
  if (pass == FrontendPass.DEFINITIONS) {
    if (newlyLoaded) {
      if (LogHelper.isDebugEnabled()) {
        LogHelper.debug(context,"String_Node_Str" + module.canonicalName);
        LogHelper.debug(context,parsed.ast.printTree());
      }
      walkFile(context,module,parsed,pass);
    }
  }
 else {
    assert(pass == FrontendPass.COMPILE_FUNCTIONS || pass == FrontendPass.COMPILE_TOPLEVEL);
    assert(!newlyLoaded);
    walkFile(context,module,parsed,pass);
  }
}

Fixed version (ground truth):
/** 
 * Compile or load definitions for a module (depending on pass), if needed. Avoids double-compiling or double loading a module.
 * @param context
 * @param pass
 * @param module
 * @throws ModuleLoadException
 * @throws UserException
 */
private void loadModule(GlobalContext context,LocalContext topLevelContext,FrontendPass pass,LocatedModule module) throws UserException {
  Pair<ParsedModule,Boolean> loaded=modules.loadIfNeeded(context,module);
  ParsedModule parsed=loaded.val1;
  boolean newlyLoaded=loaded.val2;
  if (pass == FrontendPass.DEFINITIONS) {
    if (newlyLoaded) {
      if (LogHelper.isDebugEnabled()) {
        LogHelper.debug(context,"String_Node_Str" + module.canonicalName);
        LogHelper.debug(context,parsed.ast.printTree());
      }
      walkFile(context,topLevelContext,module,parsed,pass);
    }
  }
 else {
    assert(pass == FrontendPass.COMPILE_FUNCTIONS || pass == FrontendPass.COMPILE_TOPLEVEL);
    assert(!newlyLoaded);
    walkFile(context,topLevelContext,module,parsed,pass);
  }
}
Program: 132581
Project: 132581
Buggy source:
private void loadDefinitions(GlobalContext context,LocatedModule mainModule,LocatedModule builtins) throws ModuleLoadException, UserException {
  loadModule(context,FrontendPass.DEFINITIONS,builtins);
  loadModule(context,FrontendPass.DEFINITIONS,mainModule);
}

Fixed version (ground truth):
private void loadDefinitions(GlobalContext context,LocalContext topLevelContext,LocatedModule mainModule,LocatedModule builtins) throws ModuleLoadException, UserException {
  loadModule(context,topLevelContext,FrontendPass.DEFINITIONS,builtins);
  loadModule(context,topLevelContext,FrontendPass.DEFINITIONS,mainModule);
}
Program: 132582
Project: 132582
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);
  LocalContext topLevelContext=LocalContext.topLevelContext(context);
  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,topLevelContext,mainModule,builtins);
  compileTopLevel(context,topLevelContext,mainModule);
  compileFunctions(context,topLevelContext);
}
Program: 132583
Project: 132583
Buggy source:
public void addUnifiedValues(GlobalConstants consts,String errContext,int stmtIndex,UnifiedValues unified) throws OptUnsafeError {
  for (  Var closed : unified.closed) {
    markClosed(closed,stmtIndex,false);
  }
  for (  Var closed : unified.recursivelyClosed) {
    markClosed(closed,stmtIndex,true);
  }
  update(consts,errContext,unified.availableVals,null,stmtIndex);
}

Fixed version (ground truth):
public void addUnifiedValues(GlobalConstants consts,String errContext,int stmtIndex,UnifiedValues unified) throws OptUnsafeError {
  int closedIndex=stmtIndex + 1;
  for (  Var closed : unified.closed) {
    markClosed(closed,closedIndex,false);
  }
  for (  Var closed : unified.recursivelyClosed) {
    markClosed(closed,closedIndex,true);
  }
  update(consts,errContext,unified.availableVals,null,stmtIndex);
}
Program: 132584
Project: 132584
Buggy source:
public static FunctionCall fromAST(Context context,SwiftAST tree,boolean doWarn) throws UserException {
  assert(tree.getChildCount() >= 2);
  SwiftAST fTree=tree.child(0);
  String f;
  if (fTree.getType() == ExMParser.DEPRECATED) {
    fTree=fTree.child(0);
    assert(fTree.getType() == ExMParser.ID);
    f=fTree.getText();
    if (doWarn) {
      LogHelper.warn(context,"String_Node_Str" + f + "String_Node_Str");
    }
  }
 else {
    assert(fTree.getType() == ExMParser.ID);
    f=fTree.getText();
  }
  SwiftAST arglist=tree.child(1);
  DefInfo def=context.lookupDef(f);
  List<SwiftAST> annotations=tree.children(2);
  if (def.kind == DefKind.FUNCTION) {
    FunctionType ftype=context.lookupFunction(f);
    assert(ftype != null);
    return regularFunctionFromAST(context,annotations,f,arglist,ftype);
  }
 else   if (def.kind == DefKind.TYPE) {
    Type type=context.lookupTypeUnsafe(f);
    assert(type != null);
    if (Types.isStruct(type)) {
      return structConstructorFromAST(context,annotations,f,arglist,type);
    }
  }
  throw UndefinedFunctionException.unknownFunction(context,f);
}

Fixed version (ground truth):
public static FunctionCall fromAST(Context context,SwiftAST tree,boolean doWarn) throws UserException {
  assert(tree.getChildCount() >= 2);
  SwiftAST fTree=tree.child(0);
  String f;
  if (fTree.getType() == ExMParser.DEPRECATED) {
    fTree=fTree.child(0);
    assert(fTree.getType() == ExMParser.ID);
    f=fTree.getText();
    if (doWarn) {
      LogHelper.warn(context,"String_Node_Str" + f + "String_Node_Str");
    }
  }
 else {
    assert(fTree.getType() == ExMParser.ID);
    f=fTree.getText();
  }
  SwiftAST arglist=tree.child(1);
  DefInfo def=context.lookupDef(f);
  List<SwiftAST> annotations=tree.children(2);
  if (def == null) {
    throw UndefinedFunctionException.unknownFunction(context,f);
  }
 else   if (def.kind == DefKind.FUNCTION) {
    FunctionType ftype=context.lookupFunction(f);
    assert(ftype != null);
    return regularFunctionFromAST(context,annotations,f,arglist,ftype);
  }
 else   if (def.kind == DefKind.TYPE) {
    Type type=context.lookupTypeUnsafe(f);
    assert(type != null);
    if (Types.isStruct(type)) {
      return structConstructorFromAST(context,annotations,f,arglist,type);
    }
  }
  throw new TypeMismatchException(f + "String_Node_Str" + "String_Node_Str");
}
Program: 132585
Project: 132585
Buggy source:
/** 
 * Fix up any variables missing from the usedVariables passed through continuations. This is useful because it is easier to write other optimizations if they are allowed to mess up the usedVariables
 * @param updateLists modify tree and update pass and keep open lists
 */
public static void fixupProgram(Logger logger,Program prog,boolean updateLists){
  Set<Var> referencedGlobals=new HashSet<Var>();
  for (  Function fn : prog.getFunctions()) {
    if (updateLists) {
      fixupFunction(logger,prog.constants(),prog.globalVars(),fn,referencedGlobals,FixupVarMode.REBUILD);
      fixupFunction(logger,prog.constants(),prog.globalVars(),fn,referencedGlobals,FixupVarMode.ADD);
    }
 else {
      fixupFunction(logger,prog.constants(),prog.globalVars(),fn,referencedGlobals,FixupVarMode.NO_UPDATE);
    }
  }
  if (updateLists)   removeUnusedGlobals(prog.constants(),referencedGlobals);
}

Fixed version (ground truth):
/** 
 * Fix up any variables missing from the usedVariables passed through continuations. This is useful because it is easier to write other optimizations if they are allowed to mess up the usedVariables
 * @param updateLists modify tree and update pass and keep open lists
 */
public static void fixupProgram(Logger logger,Program prog,boolean updateLists){
  Set<Var> referencedGlobals=new HashSet<Var>();
  for (  Function fn : prog.getFunctions()) {
    if (updateLists) {
      fixupFunction(logger,prog.constants(),prog.globalVars(),fn,referencedGlobals,FixupVarMode.REBUILD);
      fixupFunction(logger,prog.constants(),prog.globalVars(),fn,referencedGlobals,FixupVarMode.ADD);
    }
 else {
      fixupFunction(logger,prog.constants(),prog.globalVars(),fn,referencedGlobals,FixupVarMode.NO_UPDATE);
    }
  }
  if (updateLists)   removeUnusedGlobals(prog.constants(),prog.globalVars(),referencedGlobals);
}
Program: 132586
Project: 132586
Buggy source:
private static void removeUnusedGlobals(GlobalConstants constants,Set<Var> referencedGlobals){
  Set<Var> globNames=new HashSet<Var>(constants.map().keySet());
  globNames.removeAll(referencedGlobals);
  for (  Var unused : globNames) {
    constants.remove(unused);
  }
}

Fixed version (ground truth):
private static void removeUnusedGlobals(GlobalConstants constants,GlobalVars globalVars,Set<Var> referencedGlobals){
  Set<Var> globalsToRemove=new HashSet<Var>();
  globalsToRemove.addAll(constants.map().keySet());
  globalsToRemove.addAll(globalVars.vars());
  globalsToRemove.removeAll(referencedGlobals);
  for (  Var unused : globalsToRemove) {
    if (unused.storage() == Alloc.GLOBAL_CONST) {
      constants.remove(unused);
    }
 else {
      assert(unused.storage() == Alloc.GLOBAL_VAR);
      globalVars.removeVariable(unused);
    }
  }
}
Program: 132587
Project: 132587
Buggy source:
/** 
 * Try to hoist this instruction
 * @param logger
 * @param inst
 * @param state
 * @return true if hoisted
 */
private boolean tryHoist(Logger logger,Instruction inst,HoistTracking state){
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + inst + "String_Node_Str"+ state.maxHoist+ "String_Node_Str"+ state.maxLoopHoist);
  }
  if (!inst.canChangeTiming()) {
    logger.trace("String_Node_Str");
    return false;
  }
  int maxHoist=state.maxHoist;
  for (  Arg in : inst.getInputs()) {
    if (maxHoist <= 0)     return false;
    if (in.isVar()) {
      Var inVar=in.getVar();
      maxHoist=Math.min(maxHoist,maxInputHoist(logger,state,inVar));
      if (!Semantics.canPassToChildTask(inVar)) {
        return false;
      }
    }
  }
  for (  Var readOutput : inst.getReadOutputs()) {
    int inputHoist=maxInputHoist(logger,state,readOutput);
    maxHoist=Math.min(maxHoist,inputHoist);
    logger.trace("String_Node_Str" + inputHoist + "String_Node_Str"+ readOutput.name());
  }
  for (  Var out : inst.getOutputs()) {
    if (!Semantics.canPassToChildTask(out)) {
      return false;
    }
    if (trackDeclares(out)) {
      int declareDepth=state.declareMap.getDepth(out);
      if (logger.isTraceEnabled())       logger.trace("String_Node_Str" + out + "String_Node_Str"+ declareDepth);
      assert(declareDepth >= 0);
      if (declareDepth > state.maxLoopHoist && !inst.isIdempotent()) {
        maxHoist=Math.min(maxHoist,state.maxLoopHoist);
        if (logger.isTraceEnabled())         logger.trace("String_Node_Str" + state.maxLoopHoist);
      }
    }
  }
  for (  Var out : inst.getPiecewiseAssignedOutputs()) {
    if (!inst.isIdempotent()) {
      maxHoist=Math.min(maxHoist,state.maxLoopHoist);
      if (logger.isTraceEnabled())       logger.trace("String_Node_Str" + out + "String_Node_Str"+ "String_Node_Str"+ state.maxLoopHoist);
    }
  }
  for (  Var out : inst.getOutputs()) {
    if (Types.outputRequiresInitialization(out)) {
      if (!inst.isInitialized(out)) {
        int initDepth=state.initializedMap.getDepth(out);
        if (logger.isTraceEnabled())         logger.trace("String_Node_Str" + initDepth + "String_Node_Str"+ "String_Node_Str"+ out);
        maxHoist=Math.min(maxHoist,initDepth);
        return false;
      }
    }
  }
  if (logger.isTraceEnabled())   logger.trace("String_Node_Str" + maxHoist);
  if (maxHoist <= 0) {
    return false;
  }
  int maxCorrectContext=maxHoistContext(logger,state,inst.execMode(),maxHoist);
  maxHoist=Math.max(maxHoist,maxCorrectContext);
  if (maxHoist <= 0) {
    return false;
  }
  doHoist(logger,inst,maxHoist,state);
  return true;
}

Fixed version (ground truth):
/** 
 * Try to hoist this instruction
 * @param logger
 * @param inst
 * @param state
 * @return true if hoisted
 */
private boolean tryHoist(Logger logger,Instruction inst,HoistTracking state){
}
Program: 132592
Project: 132592
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: 132593
Project: 132593
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: 132594
Project: 132594
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: 132595
Project: 132595
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: 132596
Project: 132596
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: 132597
Project: 132597
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: 132598
Project: 132598
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: 132599
Project: 132599
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: 132600
Project: 132600
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: 132601
Project: 132601
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: 132602
Project: 132602
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: 132604
Project: 132604
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: 132605
Project: 132605
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: 132606
Project: 132606
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: 132607
Project: 132607
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: 132608
Project: 132608
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: 132609
Project: 132609
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: 132610
Project: 132610
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));
}