Program: 132909
Project: 132909
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 (!Types.isArrayKeyFuture(lval.var,indexType)) {
    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.lookupVarUser(lval.varName);
    Type memberType=lval.getType(context,1);
    Var mVar;
    if (Types.isArray(memberType)) {
      Long literal=Literals.extractIntLit(context,indexExpr.child(0));
      if (literal != null) {
        long arrIx=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.createTmp(context,new RefType(memberType));
          backend.arrayRefCreateNestedImm(mVar,origLval.var,lvalArr,Arg.createIntLit(arrIx));
        }
      }
 else {
        mVar=varCreator.createTmp(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()));
  }
}

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 (!Types.isArrayKeyFuture(lval.var,indexType)) {
    throw new TypeMismatchException(context,"String_Node_Str" + "String_Node_Str" + Types.arrayKeyType(lval.var) + "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.lookupVarUser(lval.varName);
    Type memberType=lval.getType(context,1);
    Var mVar;
    if (Types.isArray(memberType)) {
      Long literal=Literals.extractIntLit(context,indexExpr.child(0));
      if (literal != null) {
        long arrIx=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.createTmp(context,new RefType(memberType));
          backend.arrayRefCreateNestedImm(mVar,origLval.var,lvalArr,Arg.createIntLit(arrIx));
        }
      }
 else {
        mVar=varCreator.createTmp(context,new RefType(memberType));
        Type keyType=Types.arrayKeyType(lvalArr);
        Var indexVar=exprWalker.eval(context,indexExpr.child(0),keyType,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()));
  }
}