Program: 133061
Project: 133061
Buggy source:
/** 
 * Handle a prefix of array lookups for the assign target
 * @param afterActions 
 * @throws UserException
 * @throws UndefinedTypeException
 * @throws TypeMismatchException 
 */
private LValue reduceArrayLVal(Context context,LValue origLval,LValue lval,SwiftAST rValExpr,Type rValType,Deque<Runnable> afterActions) throws TypeMismatchException, UndefinedTypeException, UserException {
  SwiftAST indexExpr=lval.indices.get(0);
  assert(indexExpr.getType() == ExMParser.ARRAY_PATH);
  assert(indexExpr.getChildCount() == 1);
  Type indexType=TypeChecker.findSingleExprType(context,indexExpr.child(0));
  if (!indexType.assignableTo(Types.F_INT)) {
    throw new TypeMismatchException(context,"String_Node_Str" + "String_Node_Str" + indexType.typeName());
  }
  if (lval.indices.size() == 1) {
    Var lookedup=assignTo1DArray(context,origLval,lval,rValExpr,rValType,afterActions);
    return new LValue(lval.tree,lookedup,new ArrayList<SwiftAST>());
  }
 else {
    Var lvalArr=context.getDeclaredVariable(lval.varName);
    Type memberType=lval.getType(context,1);
    Var mVar;
    if (Types.isArray(memberType)) {
      String literal=Literals.extractIntLit(context,indexExpr.child(0));
      if (literal != null) {
        long arrIx=Long.parseLong(literal);
        if (Types.isArray(lvalArr.type())) {
          mVar=varCreator.createTmpAlias(context,memberType);
          backend.arrayCreateNestedImm(mVar,lvalArr,Arg.createIntLit(arrIx));
        }
 else {
          assert(Types.isArrayRef(lvalArr.type()));
          mVar=varCreator.createTmpAlias(context,new RefType(memberType));
          backend.arrayRefCreateNestedImm(mVar,origLval.var,lvalArr,Arg.createIntLit(arrIx));
        }
      }
 else {
        mVar=varCreator.createTmpAlias(context,new RefType(memberType));
        Var indexVar=exprWalker.eval(context,indexExpr.child(0),Types.F_INT,false,null);
        if (Types.isArray(lvalArr.type())) {
          backend.arrayCreateNestedFuture(mVar,lvalArr,indexVar);
        }
 else {
          assert(Types.isArrayRef(lvalArr.type()));
          backend.arrayRefCreateNestedFuture(mVar,lvalArr,indexVar,origLval.var);
        }
      }
    }
 else {
      mVar=varCreator.createTmp(context,new RefType(memberType));
    }
    return new LValue(lval.tree,mVar,lval.indices.subList(1,lval.indices.size()));
  }
}

Fixed version (ground truth):
/** 
 * Handle a prefix of array lookups for the assign target
 * @param afterActions 
 * @throws UserException
 * @throws UndefinedTypeException
 * @throws TypeMismatchException 
 */
private LValue reduceArrayLVal(Context context,LValue origLval,LValue lval,SwiftAST rValExpr,Type rValType,Deque<Runnable> afterActions) throws TypeMismatchException, UndefinedTypeException, UserException {
  SwiftAST indexExpr=lval.indices.get(0);
  assert(indexExpr.getType() == ExMParser.ARRAY_PATH);
  assert(indexExpr.getChildCount() == 1);
  Type indexType=TypeChecker.findSingleExprType(context,indexExpr.child(0));
  if (!indexType.assignableTo(Types.F_INT)) {
    throw new TypeMismatchException(context,"String_Node_Str" + "String_Node_Str" + indexType.typeName());
  }
  if (lval.indices.size() == 1) {
    Var lookedup=assignTo1DArray(context,origLval,lval,rValExpr,rValType,afterActions);
    return new LValue(lval.tree,lookedup,new ArrayList<SwiftAST>());
  }
 else {
    Var lvalArr=context.getDeclaredVariable(lval.varName);
    Type memberType=lval.getType(context,1);
    Var mVar;
    if (Types.isArray(memberType)) {
      String literal=Literals.extractIntLit(context,indexExpr.child(0));
      if (literal != null) {
        long arrIx=Long.parseLong(literal);
        if (Types.isArray(lvalArr.type())) {
          mVar=varCreator.createTmpAlias(context,memberType);
          backend.arrayCreateNestedImm(mVar,lvalArr,Arg.createIntLit(arrIx));
        }
 else {
          assert(Types.isArrayRef(lvalArr.type()));
          mVar=varCreator.createTmpAlias(context,new RefType(memberType));
          backend.arrayRefCreateNestedImm(mVar,origLval.var,lvalArr,Arg.createIntLit(arrIx));
        }
      }
 else {
        mVar=varCreator.createTmpAlias(context,new RefType(memberType));
        Var indexVar=exprWalker.eval(context,indexExpr.child(0),Types.F_INT,false,null);
        if (Types.isArray(lvalArr.type())) {
          backend.arrayCreateNestedFuture(mVar,lvalArr,indexVar);
        }
 else {
          assert(Types.isArrayRef(lvalArr.type()));
          backend.arrayRefCreateNestedFuture(mVar,origLval.var,lvalArr,indexVar);
        }
      }
    }
 else {
      mVar=varCreator.createTmp(context,new RefType(memberType));
    }
    return new LValue(lval.tree,mVar,lval.indices.subList(1,lval.indices.size()));
  }
}