Program: 133246
Project: 133246
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,Variable 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);
  SwiftType arrExprType=TypeChecker.findSingleExprType(context,arrayTree);
  Variable arrayVar=evalExprToTmp(context,arrayTree,arrExprType,false,renames);
  boolean isRef;
  SwiftType arrayType=arrayVar.getType();
  SwiftType memberType;
  if (Types.isArray(arrayType)) {
    isRef=false;
    memberType=arrayType.getMemberType();
  }
 else   if (Types.isArrayRef(arrayType)) {
    isRef=true;
    memberType=arrayType.getMemberType().getMemberType();
  }
 else {
    throw new TypeMismatchException(context,"String_Node_Str" + "String_Node_Str");
  }
  if (Types.isArray(memberType)) {
    if (!(Types.isArrayRef(oVar.getType()) && oVar.getType().getMemberType().equals(memberType))) {
      SwiftType expType=new Types.ReferenceType(memberType);
      throw new TypeMismatchException(context,"String_Node_Str" + expType.toString() + "String_Node_Str"+ arrayVar.getName()+ "String_Node_Str"+ arrayVar.getType().toString()+ "String_Node_Str"+ oVar.getType().toString());
    }
  }
 else   if (Types.isStruct(memberType)) {
    if (!(Types.isStructRef(oVar.getType()) && oVar.getType().getMemberType().equals(memberType))) {
      SwiftType expType=new Types.ReferenceType(memberType);
      throw new TypeMismatchException(context,"String_Node_Str" + expType.toString() + "String_Node_Str"+ arrayVar.getName()+ "String_Node_Str"+ arrayVar.getType().toString()+ "String_Node_Str"+ oVar.getType().toString());
    }
  }
 else   if (Types.isScalarFuture(memberType)) {
    if (!memberType.equals(oVar.getType())) {
      throw new TypeMismatchException(context,"String_Node_Str" + arrayVar.toString() + "String_Node_Str"+ oVar.toString());
    }
  }
 else {
    throw new STCRuntimeError("String_Node_Str" + "String_Node_Str" + memberType.toString());
  }
  SwiftAST arrayIndexTree=tree.child(1);
  SwiftType indexType=TypeChecker.findSingleExprType(context,arrayIndexTree);
  if (!indexType.assignableTo(Types.FUTURE_INTEGER)) {
    throw new TypeMismatchException(context,"String_Node_Str" + "String_Node_Str" + indexType.typeName());
  }
  Variable lookupIntoVar;
  boolean doDereference;
  if (memberType.equals(oVar.getType())) {
    lookupIntoVar=varCreator.createTmp(context,new ReferenceType(memberType));
    doDereference=true;
  }
 else {
    assert(Types.isReference(oVar.getType()));
    assert(memberType.equals(oVar.getType().getMemberType()));
    lookupIntoVar=oVar;
    doDereference=false;
  }
  String arrayIndexStr=Literals.extractIntLit(context,arrayIndexTree);
  if (arrayIndexStr != null) {
    long arrayIndex;
    try {
      arrayIndex=Long.parseLong(arrayIndexStr);
    }
 catch (    NumberFormatException e) {
      throw new STCRuntimeError("String_Node_Str" + arrayIndexStr);
    }
    backend.arrayLookupRefImm(lookupIntoVar,arrayVar,Arg.createIntLit(arrayIndex),isRef);
  }
 else {
    Variable indexVar=evalExprToTmp(context,arrayIndexTree,Types.FUTURE_INTEGER,false,renames);
    backend.arrayLookupFuture(lookupIntoVar,arrayVar,indexVar,isRef);
  }
  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,Variable 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);
  SwiftType arrExprType=TypeChecker.findSingleExprType(context,arrayTree);
  SwiftType arrType=null;
  for (  SwiftType altType : UnionType.getAlternatives(arrExprType)) {
    assert(Types.isArray(altType) || Types.isArrayRef(altType));
    SwiftType lookupRes=TypeChecker.dereferenceResultType(Types.getArrayMemberType(altType));
    if (lookupRes.equals(oVar.getType())) {
      arrType=altType;
      break;
    }
  }
  if (arrType == null) {
    throw new STCRuntimeError("String_Node_Str" + arrExprType + "String_Node_Str"+ oVar);
  }
  Variable arrayVar=evalExprToTmp(context,arrayTree,arrType,false,renames);
  SwiftType memberType=Types.getArrayMemberType(arrType);
  SwiftAST arrayIndexTree=tree.child(1);
  SwiftType indexType=TypeChecker.findSingleExprType(context,arrayIndexTree);
  if (!indexType.assignableTo(Types.FUTURE_INTEGER)) {
    throw new TypeMismatchException(context,"String_Node_Str" + "String_Node_Str" + indexType.typeName());
  }
  Variable lookupIntoVar;
  boolean doDereference;
  if (memberType.equals(oVar.getType())) {
    lookupIntoVar=varCreator.createTmp(context,new ReferenceType(memberType));
    doDereference=true;
  }
 else {
    assert(Types.isReferenceTo(oVar.getType(),memberType));
    lookupIntoVar=oVar;
    doDereference=false;
  }
  String arrayIndexStr=Literals.extractIntLit(context,arrayIndexTree);
  if (arrayIndexStr != null) {
    long arrayIndex;
    try {
      arrayIndex=Long.parseLong(arrayIndexStr);
    }
 catch (    NumberFormatException e) {
      throw new STCRuntimeError("String_Node_Str" + arrayIndexStr);
    }
    backend.arrayLookupRefImm(lookupIntoVar,arrayVar,Arg.createIntLit(arrayIndex),Types.isArrayRef(arrType));
  }
 else {
    Variable indexVar=evalExprToTmp(context,arrayIndexTree,Types.FUTURE_INTEGER,false,renames);
    backend.arrayLookupFuture(lookupIntoVar,arrayVar,indexVar,Types.isArrayRef(arrType));
  }
  if (doDereference) {
    dereference(context,oVar,lookupIntoVar);
  }
}