Program: 133162
Project: 133162
Buggy source:
/** 
 * Generate code for a call to a function, where the arguments might be expressions
 * @param context
 * @param tree
 * @param oList
 * @throws UserException
 * @throws UndefinedVariableException
 * @throws UndefinedFunctionException
 */
private void callFunctionExpression(Context context,SwiftAST tree,List<Var> oList,Map<String,String> renames) throws UserException {
  FunctionCall f=FunctionCall.fromAST(context,tree,true);
  FunctionType concrete=TypeChecker.concretiseFunctionCall(context,f.function(),f.type(),f.args(),oList,false);
  try {
    if (Builtins.isAssertVariant(f.function()) && Settings.getBoolean(Settings.OPT_DISABLE_ASSERTS)) {
      return;
    }
  }
 catch (  InvalidOptionException e) {
    throw new STCRuntimeError("String_Node_Str" + e.toString());
  }
  ArrayList<Var> argVars=new ArrayList<Var>(f.args().size());
  for (int i=0; i < f.args().size(); i++) {
    SwiftAST argtree=f.args().get(i);
    Type expType=concrete.getInputs().get(i);
    Type exprType=TypeChecker.findSingleExprType(context,argtree);
    Type argtype=TypeChecker.checkFunArg(context,f.function(),i,expType,exprType).val2;
    argVars.add(eval(context,argtree,argtype,false,renames));
  }
  Var priorityVal=null;
  boolean openedWait=false;
  ArrayList<Var> usedVariables=null;
  List<Var> keepOpen=RefCounting.filterWriteRefcount(oList);
  Context callContext=context;
  if (tree.getChildCount() == 3) {
    SwiftAST priorityT=tree.child(2);
    Var priorityFuture=eval(context,priorityT,Types.F_INT,false,renames);
    usedVariables=new ArrayList<Var>();
    usedVariables.addAll(argVars);
    usedVariables.addAll(oList);
    backend.startWaitStatement(context.getFunctionContext().constructName("String_Node_Str"),Arrays.asList(priorityFuture),usedVariables,keepOpen,null,WaitMode.DATA_ONLY,false,TaskMode.LOCAL_CONTROL);
    openedWait=true;
    callContext=new LocalContext(context);
    priorityVal=varCreator.fetchValueOf(callContext,priorityFuture);
  }
  callFunction(context,f.function(),concrete,oList,argVars,priorityVal);
  if (openedWait) {
    backend.endWaitStatement(usedVariables,keepOpen);
  }
}

Fixed version (ground truth):
/** 
 * Generate code for a call to a function, where the arguments might be expressions
 * @param context
 * @param tree
 * @param oList
 * @throws UserException
 * @throws UndefinedVariableException
 * @throws UndefinedFunctionException
 */
private void callFunctionExpression(Context context,SwiftAST tree,List<Var> oList,Map<String,String> renames) throws UserException {
  FunctionCall f=FunctionCall.fromAST(context,tree,true);
  FunctionType concrete=TypeChecker.concretiseFunctionCall(context,f.function(),f.type(),f.args(),oList,false);
  try {
    if (Builtins.isAssertVariant(f.function()) && Settings.getBoolean(Settings.OPT_DISABLE_ASSERTS)) {
      return;
    }
  }
 catch (  InvalidOptionException e) {
    throw new STCRuntimeError("String_Node_Str" + e.toString());
  }
  ArrayList<Var> argVars=new ArrayList<Var>(f.args().size());
  for (int i=0; i < f.args().size(); i++) {
    SwiftAST argtree=f.args().get(i);
    Type expType=concrete.getInputs().get(i);
    Type exprType=TypeChecker.findSingleExprType(context,argtree);
    Type argtype=TypeChecker.checkFunArg(context,f.function(),i,expType,exprType).val2;
    argVars.add(eval(context,argtree,argtype,false,renames));
  }
  Var priorityVal=null;
  boolean openedWait=false;
  List<Var> waitVars=null;
  List<Var> usedVariables=null;
  List<Var> keepOpen=RefCounting.filterWriteRefcount(oList);
  Context callContext=context;
  if (tree.getChildCount() == 3) {
    SwiftAST priorityT=tree.child(2);
    Var priorityFuture=eval(context,priorityT,Types.F_INT,false,renames);
    usedVariables=new ArrayList<Var>();
    usedVariables.addAll(argVars);
    usedVariables.addAll(oList);
    waitVars=Arrays.asList(priorityFuture);
    backend.startWaitStatement(context.getFunctionContext().constructName("String_Node_Str"),waitVars,usedVariables,keepOpen,null,WaitMode.DATA_ONLY,false,TaskMode.LOCAL_CONTROL);
    openedWait=true;
    callContext=new LocalContext(context);
    priorityVal=varCreator.fetchValueOf(callContext,priorityFuture);
  }
  callFunction(context,f.function(),concrete,oList,argVars,priorityVal);
  if (openedWait) {
    backend.endWaitStatement(waitVars,usedVariables,keepOpen);
  }
}