Program: 132917
Project: 132917
Buggy source:
/** 
 * Handle an expression which is an array access. Copies a member of an array, specified by index, into another variable. If the other variable is an alias variable, we can avoid the copy.
 * @param context
 * @param tree
 * @param oVar the variable to copy into
 * @throws UserException
 */
private void arrayLoad(Context context,SwiftAST tree,Var oVar,Map<String,String> renames) throws UserException {
  if (tree.getChildCount() != 2) {
    throw new STCRuntimeError("String_Node_Str" + "String_Node_Str" + tree.getChildCount());
  }
  SwiftAST arrayTree=tree.child(0);
  Type arrExprType=TypeChecker.findSingleExprType(context,arrayTree);
  Type arrType=null;
  for (  Type altType : UnionType.getAlternatives(arrExprType)) {
    assert(Types.isArray(altType) || Types.isArrayRef(altType));
    Type lookupRes=TypeChecker.dereferenceResultType(Types.arrayMemberType(altType));
    if (lookupRes.equals(oVar.type())) {
      arrType=altType;
      break;
    }
  }
  if (arrType == null) {
    throw new STCRuntimeError("String_Node_Str" + arrExprType + "String_Node_Str"+ oVar);
  }
  Var arrayVar=eval(context,arrayTree,arrType,false,renames);
  Type memberType=Types.arrayMemberType(arrType);
  SwiftAST arrayIndexTree=tree.child(1);
  Type indexType=TypeChecker.findSingleExprType(context,arrayIndexTree);
  if (!indexType.assignableTo(Types.F_INT)) {
    throw new TypeMismatchException(context,"String_Node_Str" + "String_Node_Str" + indexType.typeName());
  }
  Var lookupIntoVar;
  boolean doDereference;
  if (memberType.equals(oVar.type())) {
    lookupIntoVar=varCreator.createTmp(context,new RefType(memberType));
    doDereference=true;
  }
 else {
    assert(Types.isRefTo(oVar.type(),memberType));
    lookupIntoVar=oVar;
    doDereference=false;
  }
  Long arrayIndex=Literals.extractIntLit(context,arrayIndexTree);
  if (arrayIndex != null) {
    backend.arrayLookupRefImm(lookupIntoVar,arrayVar,Arg.createIntLit(arrayIndex),Types.isArrayRef(arrType));
  }
 else {
    Var indexVar=eval(context,arrayIndexTree,Types.F_INT,false,renames);
    backend.arrayLookupFuture(lookupIntoVar,arrayVar,indexVar,Types.isArrayRef(arrType));
  }
  if (doDereference) {
    dereference(context,oVar,lookupIntoVar);
  }
}

Fixed version (ground truth):
/** 
 * Handle an expression which is an array access. Copies a member of an array, specified by index, into another variable. If the other variable is an alias variable, we can avoid the copy.
 * @param context
 * @param tree
 * @param oVar the variable to copy into
 * @throws UserException
 */
private void arrayLoad(Context context,SwiftAST tree,Var oVar,Map<String,String> renames) throws UserException {
  if (tree.getChildCount() != 2) {
    throw new STCRuntimeError("String_Node_Str" + "String_Node_Str" + tree.getChildCount());
  }
  SwiftAST arrayTree=tree.child(0);
  Type arrExprType=TypeChecker.findSingleExprType(context,arrayTree);
  Type arrType=null;
  for (  Type altType : UnionType.getAlternatives(arrExprType)) {
    assert(Types.isArray(altType) || Types.isArrayRef(altType));
    Type lookupRes=TypeChecker.dereferenceResultType(Types.arrayMemberType(altType));
    if (lookupRes.equals(oVar.type())) {
      arrType=altType;
      break;
    }
  }
  if (arrType == null) {
    throw new STCRuntimeError("String_Node_Str" + arrExprType + "String_Node_Str"+ oVar);
  }
  Var arrayVar=eval(context,arrayTree,arrType,false,renames);
  Type memberType=Types.arrayMemberType(arrType);
  SwiftAST arrayIndexTree=tree.child(1);
  Type indexType=TypeChecker.findSingleExprType(context,arrayIndexTree);
  if (!indexType.assignableTo(Types.F_INT)) {
    throw new TypeMismatchException(context,"String_Node_Str" + "String_Node_Str" + indexType.typeName());
  }
  Var lookupIntoVar;
  boolean doDereference;
  if (memberType.equals(oVar.type())) {
    lookupIntoVar=varCreator.createTmp(context,new RefType(memberType));
    doDereference=true;
  }
 else {
    assert(Types.isAssignableRefTo(oVar.type(),memberType));
    lookupIntoVar=oVar;
    doDereference=false;
  }
  Long arrayIndex=Literals.extractIntLit(context,arrayIndexTree);
  if (arrayIndex != null) {
    backend.arrayLookupRefImm(lookupIntoVar,arrayVar,Arg.createIntLit(arrayIndex),Types.isArrayRef(arrType));
  }
 else {
    Var indexVar=eval(context,arrayIndexTree,Types.F_INT,false,renames);
    backend.arrayLookupFuture(lookupIntoVar,arrayVar,indexVar,Types.isArrayRef(arrType));
  }
  if (doDereference) {
    dereference(context,oVar,lookupIntoVar);
  }
}