Program: 61495
Project: 61495
Buggy source:
public int method(boolean isStatic,int name_index,boolean subMethod,boolean isInterface,List<MethodBody> callStack,DottedChain pkg,boolean needsActivation,List<AssignableAVM2Item> subvariables,int initScope,boolean hasRest,int line,String className,String superType,boolean constructor,SourceGeneratorLocalData localData,List<GraphTargetItem> paramTypes,List<String> paramNames,List<GraphTargetItem> paramValues,List<GraphTargetItem> body,GraphTargetItem retType) throws CompilationException {
  SourceGeneratorLocalData newlocalData=new SourceGeneratorLocalData(new HashMap<>(),1,true,0);
  newlocalData.currentClass=className;
  newlocalData.pkg=localData.pkg;
  newlocalData.callStack.addAll(localData.callStack);
  newlocalData.traitUsages=localData.traitUsages;
  newlocalData.currentScript=localData.currentScript;
  newlocalData.documentClass=localData.documentClass;
  newlocalData.privateNs=localData.privateNs;
  newlocalData.protectedNs=localData.protectedNs;
  newlocalData.isStatic=isStatic;
  newlocalData.subMethod=subMethod;
  localData=newlocalData;
  localData.activationReg=0;
  for (int i=0; i < subvariables.size(); i++) {
    AssignableAVM2Item an=subvariables.get(i);
    if (an instanceof UnresolvedAVM2Item) {
      UnresolvedAVM2Item n=(UnresolvedAVM2Item)an;
      if (n.resolved == null) {
        String fullClass=localData.getFullClass();
        GraphTargetItem res=n.resolve(new TypeItem(fullClass),paramTypes,paramNames,abcIndex,callStack,subvariables);
        if (res instanceof AssignableAVM2Item) {
          subvariables.set(i,(AssignableAVM2Item)res);
        }
 else {
          subvariables.remove(i);
          i--;
        }
      }
    }
  }
  for (int t=0; t < paramTypes.size(); t++) {
    GraphTargetItem an=paramTypes.get(t);
    if (an instanceof UnresolvedAVM2Item) {
      UnresolvedAVM2Item n=(UnresolvedAVM2Item)an;
      if (n.resolved == null) {
        String fullClass=localData.getFullClass();
        GraphTargetItem res=n.resolve(new TypeItem(fullClass),paramTypes,paramNames,abcIndex,callStack,subvariables);
        paramTypes.set(t,res);
      }
    }
  }
  boolean hasArguments=false;
  List<String> slotNames=new ArrayList<>();
  List<String> slotTypes=new ArrayList<>();
  slotNames.add("String_Node_Str");
  slotTypes.add("String_Node_Str");
  List<String> registerNames=new ArrayList<>();
  List<String> registerTypes=new ArrayList<>();
  if (className != null) {
    String fullClassName=pkg.add(className).toRawString();
    registerTypes.add(fullClassName);
    localData.scopeStack.add(new LocalRegAVM2Item(null,registerNames.size(),null));
    registerNames.add("String_Node_Str");
  }
 else {
    registerTypes.add("String_Node_Str");
    registerNames.add("String_Node_Str");
  }
  for (  GraphTargetItem t : paramTypes) {
    registerTypes.add(t.toString());
    slotTypes.add(t.toString());
  }
  registerNames.addAll(paramNames);
  slotNames.addAll(paramNames);
  if (hasRest) {
    slotTypes.add("String_Node_Str");
  }
  localData.registerVars.clear();
  for (  AssignableAVM2Item an : subvariables) {
    if (an instanceof NameAVM2Item) {
      NameAVM2Item n=(NameAVM2Item)an;
      if (n.getVariableName().equals("String_Node_Str") & !n.isDefinition()) {
        registerNames.add("String_Node_Str");
        registerTypes.add("String_Node_Str");
        hasArguments=true;
        break;
      }
    }
  }
  int paramRegCount=registerNames.size();
  if (needsActivation) {
    registerNames.add("String_Node_Str");
    localData.activationReg=registerNames.size() - 1;
    registerTypes.add("String_Node_Str");
    localData.scopeStack.add(new LocalRegAVM2Item(null,localData.activationReg,null));
  }
  String mask=Configuration.registerNameFormat.get();
  mask=mask.replace("String_Node_Str","String_Node_Str");
  Pattern pat=Pattern.compile(mask);
  for (int round=1; round <= 2; round++) {
    for (    AssignableAVM2Item an : subvariables) {
      if (an instanceof NameAVM2Item) {
        NameAVM2Item n=(NameAVM2Item)an;
        if (n.isDefinition() && !registerNames.contains(n.getVariableName())) {
          if (!needsActivation || (n.getSlotScope() <= 0)) {
            String varName=n.getVariableName();
            Matcher m=pat.matcher(varName);
            if ((round == 1) && (m.matches())) {
              String regIndexStr=m.group(1);
              int regIndex=Integer.parseInt(regIndexStr);
              while (registerNames.size() <= regIndex + 1) {
                String standardName=String.format(mask,registerNames.size() - 1);
                registerNames.add(standardName);
                registerTypes.add("String_Node_Str");
                slotNames.add(standardName);
                slotTypes.add("String_Node_Str");
              }
              registerNames.set(regIndex,varName);
              registerTypes.set(regIndex,varName);
              slotNames.set(regIndex,varName);
              slotTypes.set(regIndex,varName);
            }
 else             if (round == 2 && !m.matches()) {
              registerNames.add(n.getVariableName());
              registerTypes.add(n.type.toString());
              slotNames.add(n.getVariableName());
              slotTypes.add(n.type.toString());
            }
          }
        }
      }
    }
  }
  int slotScope=subMethod ? 0 : 1;
  for (  AssignableAVM2Item an : subvariables) {
    if (an instanceof NameAVM2Item) {
      NameAVM2Item n=(NameAVM2Item)an;
      String variableName=n.getVariableName();
      if (variableName != null) {
        boolean isThisOrSuper=variableName.equals("String_Node_Str") || variableName.equals("String_Node_Str");
        if (!isThisOrSuper && needsActivation) {
          if (n.getSlotNumber() <= 0) {
            n.setSlotNumber(slotNames.indexOf(variableName));
            n.setSlotScope(slotScope);
          }
        }
 else {
          if (isThisOrSuper) {
            n.setRegNumber(0);
          }
 else {
            n.setRegNumber(registerNames.indexOf(variableName));
          }
        }
      }
    }
  }
  for (int i=0; i < registerNames.size(); i++) {
    if (needsActivation && i > localData.activationReg) {
      break;
    }
    localData.registerVars.put(registerNames.get(i),i);
  }
  List<NameAVM2Item> declarations=new ArrayList<>();
  loopn:   for (  AssignableAVM2Item an : subvariables) {
    if (an instanceof NameAVM2Item) {
      NameAVM2Item n=(NameAVM2Item)an;
      if (needsActivation) {
        if (n.getSlotScope() != slotScope) {
          continue;
        }
 else {
          if (n.getSlotNumber() < paramRegCount) {
            continue;
          }
        }
      }
      for (      NameAVM2Item d : declarations) {
        if (n.getVariableName() != null && n.getVariableName().equals(d.getVariableName())) {
          continue loopn;
        }
      }
      for (      GraphTargetItem it : body) {
        if (it instanceof NameAVM2Item) {
          NameAVM2Item n2=(NameAVM2Item)it;
          if (n2.isDefinition() && n2.getAssignedValue() != null && n2.getVariableName().equals(n.getVariableName())) {
            continue loopn;
          }
          if (!n2.isDefinition() && n2.getVariableName() != null && n2.getVariableName().equals(n.getVariableName())) {
            break;
          }
        }
      }
      if (n.unresolved) {
        continue;
      }
      if (n.redirect != null) {
        continue;
      }
      if (n.getNs() != null) {
        continue;
      }
      String variableName=n.getVariableName();
      if ("String_Node_Str".equals(variableName) || "String_Node_Str".equals(variableName) || paramNames.contains(variableName)|| "String_Node_Str".equals(variableName)) {
        continue;
      }
      NameAVM2Item d=new NameAVM2Item(n.type,n.line,n.getVariableName(),NameAVM2Item.getDefaultValue("String_Node_Str" + n.type),true,n.openedNamespaces);
      if (needsActivation) {
        if (d.getSlotNumber() <= 0) {
          d.setSlotNumber(n.getSlotNumber());
          d.setSlotScope(n.getSlotScope());
        }
      }
 else {
        d.setRegNumber(n.getRegNumber());
      }
      declarations.add(d);
    }
  }
  int[] param_types=new int[paramTypes.size()];
  ValueKind[] optional=new ValueKind[paramValues.size()];
  for (int i=0; i < paramTypes.size(); i++) {
    param_types[i]=typeName(localData,paramTypes.get(i));
  }
  for (int i=0; i < paramValues.size(); i++) {
    optional[i]=getValueKind(Namespace.KIND_NAMESPACE,paramTypes.get(paramTypes.size() - paramValues.size() + i),paramValues.get(i));
    if (optional[i] == null) {
      throw new CompilationException("String_Node_Str",line);
    }
  }
  MethodInfo mi=new MethodInfo(param_types,constructor ? 0 : typeName(localData,retType),name_index,0,optional,new int[0]);
  if (hasArguments) {
    mi.setFlagNeed_Arguments();
  }
  if (!paramValues.isEmpty()) {
    mi.setFlagHas_optional();
  }
  if (hasRest) {
    mi.setFlagNeed_rest();
  }
  int mindex;
  if (!isInterface) {
    MethodBody mbody=new MethodBody(abcIndex.getSelectedAbc(),new Traits(),new byte[0],new ABCException[0]);
    if (needsActivation) {
      int slotId=1;
      for (int i=1; i < slotNames.size(); i++) {
        TraitSlotConst tsc=new TraitSlotConst();
        tsc.slot_id=slotId++;
        tsc.name_index=abcIndex.getSelectedAbc().constants.getMultinameId(new Multiname(Multiname.QNAME,abcIndex.getSelectedAbc().constants.getStringId(slotNames.get(i),true),abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE_INTERNAL,pkg,0,true),0),true);
        tsc.type_index=typeName(localData,new TypeItem(slotTypes.get(i)));
        mbody.traits.traits.add(tsc);
      }
      for (int i=1; i < paramRegCount; i++) {
        NameAVM2Item param=new NameAVM2Item(new TypeItem(registerTypes.get(i)),0,registerNames.get(i),null,false,new ArrayList<>());
        param.setRegNumber(i);
        NameAVM2Item d=new NameAVM2Item(new TypeItem(registerTypes.get(i)),0,registerNames.get(i),param,true,new ArrayList<>());
        d.setSlotScope(slotScope);
        d.setSlotNumber(slotNames.indexOf(registerNames.get(i)));
        declarations.add(d);
      }
    }
    if (body != null) {
      body.addAll(0,declarations);
    }
    localData.exceptions=new ArrayList<>();
    localData.callStack.add(mbody);
    List<GraphSourceItem> src=body == null ? new ArrayList<>() : generate(localData,body);
    mbody.method_info=abcIndex.getSelectedAbc().addMethodInfo(mi);
    mi.setBody(mbody);
    List<AVM2Instruction> mbodyCode=toInsList(src);
    mbody.setCode(new AVM2Code());
    mbody.getCode().code=mbodyCode;
    if (needsActivation) {
      if (localData.traitUsages.containsKey(mbody)) {
        List<Integer> usages=localData.traitUsages.get(mbody);
        for (int i=0; i < mbody.traits.traits.size(); i++) {
          if (usages.contains(i)) {
            TraitSlotConst tsc=(TraitSlotConst)mbody.traits.traits.get(i);
            GraphTargetItem type=TypeItem.UNBOUNDED;
            if (tsc.type_index > 0) {
              type=new TypeItem(abcIndex.getSelectedAbc().constants.getMultiname(tsc.type_index).getNameWithNamespace(abcIndex.getSelectedAbc().constants));
            }
            NameAVM2Item d=new NameAVM2Item(type,0,tsc.getName(abcIndex.getSelectedAbc()).getName(abcIndex.getSelectedAbc().constants,null,true),NameAVM2Item.getDefaultValue("String_Node_Str" + type),true,new ArrayList<>());
            d.setSlotNumber(tsc.slot_id);
            d.setSlotScope(slotScope);
            mbodyCode.addAll(0,toInsList(d.toSourceIgnoreReturnValue(localData,this)));
          }
        }
      }
      List<AVM2Instruction> acts=new ArrayList<>();
      acts.add(ins(AVM2Instructions.NewActivation));
      acts.add(ins(AVM2Instructions.Dup));
      acts.add(AssignableAVM2Item.generateSetLoc(localData.activationReg));
      acts.add(ins(AVM2Instructions.PushScope));
      mbodyCode.addAll(0,acts);
    }
    if (constructor) {
      int parentConstMinAC=0;
      AbcIndexing.ClassIndex ci=abcIndex.findClass(new TypeItem(superType));
      if (ci != null) {
        MethodInfo pmi=ci.abc.method_info.get(ci.abc.instance_info.get(ci.index).iinit_index);
        parentConstMinAC=pmi.param_types.length;
        if (pmi.flagHas_optional()) {
          parentConstMinAC-=pmi.optional.length;
        }
      }
      int ac=-1;
      for (      AVM2Instruction ins : mbodyCode) {
        if (ins.definition instanceof ConstructSuperIns) {
          ac=ins.operands[0];
          if (parentConstMinAC > ac) {
            throw new CompilationException("String_Node_Str",line);
          }
        }
      }
      if (ac == -1) {
        if (parentConstMinAC == 0) {
          mbodyCode.add(0,new AVM2Instruction(0,AVM2Instructions.GetLocal0,null));
          mbodyCode.add(1,new AVM2Instruction(0,AVM2Instructions.ConstructSuper,new int[]{0}));
        }
 else {
          throw new CompilationException("String_Node_Str",line);
        }
      }
    }
    if (className != null && !subMethod) {
      mbodyCode.add(0,new AVM2Instruction(0,AVM2Instructions.GetLocal0,null));
      mbodyCode.add(1,new AVM2Instruction(0,AVM2Instructions.PushScope,null));
    }
    boolean addRet=false;
    if (!mbodyCode.isEmpty()) {
      InstructionDefinition lastDef=mbodyCode.get(mbodyCode.size() - 1).definition;
      if (!((lastDef instanceof ReturnVoidIns) || (lastDef instanceof ReturnValueIns))) {
        addRet=true;
      }
    }
 else {
      addRet=true;
    }
    if (addRet) {
      if (retType.toString().equals("String_Node_Str") || retType.toString().equals("String_Node_Str") || constructor) {
        mbodyCode.add(new AVM2Instruction(0,AVM2Instructions.ReturnVoid,null));
      }
 else {
        mbodyCode.add(new AVM2Instruction(0,AVM2Instructions.PushUndefined,null));
        mbodyCode.add(new AVM2Instruction(0,AVM2Instructions.ReturnValue,null));
      }
    }
    mbody.exceptions=localData.exceptions.toArray(new ABCException[localData.exceptions.size()]);
    int offset=0;
    for (int i=0; i < mbodyCode.size(); i++) {
      AVM2Instruction ins=mbodyCode.get(i);
      if (ins instanceof ExceptionMarkAVM2Instruction) {
        ExceptionMarkAVM2Instruction m=(ExceptionMarkAVM2Instruction)ins;
switch (m.markType) {
case MARK_E_START:
          mbody.exceptions[m.exceptionId].start=offset;
        break;
case MARK_E_END:
      mbody.exceptions[m.exceptionId].end=offset;
    break;
case MARK_E_TARGET:
  mbody.exceptions[m.exceptionId].target=offset;
break;
}
mbodyCode.remove(i);
i--;
continue;
}
offset+=ins.getBytesLength();
}
mbody.markOffsets();
mbody.autoFillStats(abcIndex.getSelectedAbc(),initScope,className != null);
abcIndex.getSelectedAbc().addMethodBody(mbody);
mindex=mbody.method_info;
}
 else {
mindex=abcIndex.getSelectedAbc().addMethodInfo(mi);
}
return mindex;
}

Fixed version (ground truth):
public int method(boolean isStatic,int name_index,boolean subMethod,boolean isInterface,List<MethodBody> callStack,DottedChain pkg,boolean needsActivation,List<AssignableAVM2Item> subvariables,int initScope,boolean hasRest,int line,String className,String superType,boolean constructor,SourceGeneratorLocalData localData,List<GraphTargetItem> paramTypes,List<String> paramNames,List<GraphTargetItem> paramValues,List<GraphTargetItem> body,GraphTargetItem retType) throws CompilationException {
  SourceGeneratorLocalData newlocalData=new SourceGeneratorLocalData(new HashMap<>(),1,true,0);
  newlocalData.currentClass=className;
  newlocalData.pkg=localData.pkg;
  newlocalData.callStack.addAll(localData.callStack);
  newlocalData.traitUsages=localData.traitUsages;
  newlocalData.currentScript=localData.currentScript;
  newlocalData.documentClass=localData.documentClass;
  newlocalData.privateNs=localData.privateNs;
  newlocalData.protectedNs=localData.protectedNs;
  newlocalData.isStatic=isStatic;
  newlocalData.subMethod=subMethod;
  localData=newlocalData;
  localData.activationReg=0;
  for (int i=0; i < subvariables.size(); i++) {
    AssignableAVM2Item an=subvariables.get(i);
    if (an instanceof UnresolvedAVM2Item) {
      UnresolvedAVM2Item n=(UnresolvedAVM2Item)an;
      if (n.resolved == null) {
        String fullClass=localData.getFullClass();
        GraphTargetItem res=n.resolve(new TypeItem(fullClass),paramTypes,paramNames,abcIndex,callStack,subvariables);
        if (res instanceof AssignableAVM2Item) {
          subvariables.set(i,(AssignableAVM2Item)res);
        }
 else {
          subvariables.remove(i);
          i--;
        }
      }
    }
  }
  for (int t=0; t < paramTypes.size(); t++) {
    GraphTargetItem an=paramTypes.get(t);
    if (an instanceof UnresolvedAVM2Item) {
      UnresolvedAVM2Item n=(UnresolvedAVM2Item)an;
      if (n.resolved == null) {
        String fullClass=localData.getFullClass();
        GraphTargetItem res=n.resolve(new TypeItem(fullClass),paramTypes,paramNames,abcIndex,callStack,subvariables);
        paramTypes.set(t,res);
      }
    }
  }
  boolean hasArguments=false;
  List<String> slotNames=new ArrayList<>();
  List<String> slotTypes=new ArrayList<>();
  slotNames.add("String_Node_Str");
  slotTypes.add("String_Node_Str");
  List<String> registerNames=new ArrayList<>();
  List<String> registerTypes=new ArrayList<>();
  if (className != null) {
    String fullClassName=pkg.add(className).toRawString();
    registerTypes.add(fullClassName);
    localData.scopeStack.add(new LocalRegAVM2Item(null,registerNames.size(),null));
    registerNames.add("String_Node_Str");
  }
 else {
    registerTypes.add("String_Node_Str");
    registerNames.add("String_Node_Str");
  }
  for (  GraphTargetItem t : paramTypes) {
    registerTypes.add(t.toString());
    slotTypes.add(t.toString());
  }
  registerNames.addAll(paramNames);
  slotNames.addAll(paramNames);
  if (hasRest) {
    registerTypes.add("String_Node_Str");
    slotTypes.add("String_Node_Str");
  }
  localData.registerVars.clear();
  for (  AssignableAVM2Item an : subvariables) {
    if (an instanceof NameAVM2Item) {
      NameAVM2Item n=(NameAVM2Item)an;
      if (n.getVariableName().equals("String_Node_Str") & !n.isDefinition()) {
        registerNames.add("String_Node_Str");
        registerTypes.add("String_Node_Str");
        hasArguments=true;
        break;
      }
    }
  }
  int paramRegCount=registerNames.size();
  if (needsActivation) {
    registerNames.add("String_Node_Str");
    localData.activationReg=registerNames.size() - 1;
    registerTypes.add("String_Node_Str");
    localData.scopeStack.add(new LocalRegAVM2Item(null,localData.activationReg,null));
  }
  String mask=Configuration.registerNameFormat.get();
  mask=mask.replace("String_Node_Str","String_Node_Str");
  Pattern pat=Pattern.compile(mask);
  for (int round=1; round <= 2; round++) {
    for (    AssignableAVM2Item an : subvariables) {
      if (an instanceof NameAVM2Item) {
        NameAVM2Item n=(NameAVM2Item)an;
        if (n.isDefinition() && !registerNames.contains(n.getVariableName())) {
          if (!needsActivation || (n.getSlotScope() <= 0)) {
            String varName=n.getVariableName();
            Matcher m=pat.matcher(varName);
            if ((round == 1) && (m.matches())) {
              String regIndexStr=m.group(1);
              int regIndex=Integer.parseInt(regIndexStr);
              while (registerNames.size() <= regIndex + 1) {
                String standardName=String.format(mask,registerNames.size() - 1);
                registerNames.add(standardName);
                registerTypes.add("String_Node_Str");
                slotNames.add(standardName);
                slotTypes.add("String_Node_Str");
              }
              registerNames.set(regIndex,varName);
              registerTypes.set(regIndex,varName);
              slotNames.set(regIndex,varName);
              slotTypes.set(regIndex,varName);
            }
 else             if (round == 2 && !m.matches()) {
              registerNames.add(n.getVariableName());
              registerTypes.add(n.type.toString());
              slotNames.add(n.getVariableName());
              slotTypes.add(n.type.toString());
            }
          }
        }
      }
    }
  }
  int slotScope=subMethod ? 0 : 1;
  for (  AssignableAVM2Item an : subvariables) {
    if (an instanceof NameAVM2Item) {
      NameAVM2Item n=(NameAVM2Item)an;
      String variableName=n.getVariableName();
      if (variableName != null) {
        boolean isThisOrSuper=variableName.equals("String_Node_Str") || variableName.equals("String_Node_Str");
        if (!isThisOrSuper && needsActivation) {
          if (n.getSlotNumber() <= 0) {
            n.setSlotNumber(slotNames.indexOf(variableName));
            n.setSlotScope(slotScope);
          }
        }
 else {
          if (isThisOrSuper) {
            n.setRegNumber(0);
          }
 else {
            n.setRegNumber(registerNames.indexOf(variableName));
          }
        }
      }
    }
  }
  for (int i=0; i < registerNames.size(); i++) {
    if (needsActivation && i > localData.activationReg) {
      break;
    }
    localData.registerVars.put(registerNames.get(i),i);
  }
  List<NameAVM2Item> declarations=new ArrayList<>();
  loopn:   for (  AssignableAVM2Item an : subvariables) {
    if (an instanceof NameAVM2Item) {
      NameAVM2Item n=(NameAVM2Item)an;
      if (needsActivation) {
        if (n.getSlotScope() != slotScope) {
          continue;
        }
 else {
          if (n.getSlotNumber() < paramRegCount) {
            continue;
          }
        }
      }
      for (      NameAVM2Item d : declarations) {
        if (n.getVariableName() != null && n.getVariableName().equals(d.getVariableName())) {
          continue loopn;
        }
      }
      for (      GraphTargetItem it : body) {
        if (it instanceof NameAVM2Item) {
          NameAVM2Item n2=(NameAVM2Item)it;
          if (n2.isDefinition() && n2.getAssignedValue() != null && n2.getVariableName().equals(n.getVariableName())) {
            continue loopn;
          }
          if (!n2.isDefinition() && n2.getVariableName() != null && n2.getVariableName().equals(n.getVariableName())) {
            break;
          }
        }
      }
      if (n.unresolved) {
        continue;
      }
      if (n.redirect != null) {
        continue;
      }
      if (n.getNs() != null) {
        continue;
      }
      String variableName=n.getVariableName();
      if ("String_Node_Str".equals(variableName) || "String_Node_Str".equals(variableName) || paramNames.contains(variableName)|| "String_Node_Str".equals(variableName)) {
        continue;
      }
      NameAVM2Item d=new NameAVM2Item(n.type,n.line,n.getVariableName(),NameAVM2Item.getDefaultValue("String_Node_Str" + n.type),true,n.openedNamespaces);
      if (needsActivation) {
        if (d.getSlotNumber() <= 0) {
          d.setSlotNumber(n.getSlotNumber());
          d.setSlotScope(n.getSlotScope());
        }
      }
 else {
        d.setRegNumber(n.getRegNumber());
      }
      declarations.add(d);
    }
  }
  int[] param_types=new int[paramTypes.size()];
  ValueKind[] optional=new ValueKind[paramValues.size()];
  for (int i=0; i < paramTypes.size(); i++) {
    param_types[i]=typeName(localData,paramTypes.get(i));
  }
  for (int i=0; i < paramValues.size(); i++) {
    optional[i]=getValueKind(Namespace.KIND_NAMESPACE,paramTypes.get(paramTypes.size() - paramValues.size() + i),paramValues.get(i));
    if (optional[i] == null) {
      throw new CompilationException("String_Node_Str",line);
    }
  }
  MethodInfo mi=new MethodInfo(param_types,constructor ? 0 : typeName(localData,retType),name_index,0,optional,new int[0]);
  if (hasArguments) {
    mi.setFlagNeed_Arguments();
  }
  if (!paramValues.isEmpty()) {
    mi.setFlagHas_optional();
  }
  if (hasRest) {
    mi.setFlagNeed_rest();
  }
  int mindex;
  if (!isInterface) {
    MethodBody mbody=new MethodBody(abcIndex.getSelectedAbc(),new Traits(),new byte[0],new ABCException[0]);
    if (needsActivation) {
      int slotId=1;
      for (int i=1; i < slotNames.size(); i++) {
        TraitSlotConst tsc=new TraitSlotConst();
        tsc.slot_id=slotId++;
        tsc.name_index=abcIndex.getSelectedAbc().constants.getMultinameId(new Multiname(Multiname.QNAME,abcIndex.getSelectedAbc().constants.getStringId(slotNames.get(i),true),abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE_INTERNAL,pkg,0,true),0),true);
        tsc.type_index=typeName(localData,new TypeItem(slotTypes.get(i)));
        mbody.traits.traits.add(tsc);
      }
      for (int i=1; i < paramRegCount; i++) {
        NameAVM2Item param=new NameAVM2Item(new TypeItem(registerTypes.get(i)),0,registerNames.get(i),null,false,new ArrayList<>());
        param.setRegNumber(i);
        NameAVM2Item d=new NameAVM2Item(new TypeItem(registerTypes.get(i)),0,registerNames.get(i),param,true,new ArrayList<>());
        d.setSlotScope(slotScope);
        d.setSlotNumber(slotNames.indexOf(registerNames.get(i)));
        declarations.add(d);
      }
    }
    if (body != null) {
      body.addAll(0,declarations);
    }
    localData.exceptions=new ArrayList<>();
    localData.callStack.add(mbody);
    List<GraphSourceItem> src=body == null ? new ArrayList<>() : generate(localData,body);
    mbody.method_info=abcIndex.getSelectedAbc().addMethodInfo(mi);
    mi.setBody(mbody);
    List<AVM2Instruction> mbodyCode=toInsList(src);
    mbody.setCode(new AVM2Code());
    mbody.getCode().code=mbodyCode;
    if (needsActivation) {
      if (localData.traitUsages.containsKey(mbody)) {
        List<Integer> usages=localData.traitUsages.get(mbody);
        for (int i=0; i < mbody.traits.traits.size(); i++) {
          if (usages.contains(i)) {
            TraitSlotConst tsc=(TraitSlotConst)mbody.traits.traits.get(i);
            GraphTargetItem type=TypeItem.UNBOUNDED;
            if (tsc.type_index > 0) {
              type=new TypeItem(abcIndex.getSelectedAbc().constants.getMultiname(tsc.type_index).getNameWithNamespace(abcIndex.getSelectedAbc().constants));
            }
            NameAVM2Item d=new NameAVM2Item(type,0,tsc.getName(abcIndex.getSelectedAbc()).getName(abcIndex.getSelectedAbc().constants,null,true),NameAVM2Item.getDefaultValue("String_Node_Str" + type),true,new ArrayList<>());
            d.setSlotNumber(tsc.slot_id);
            d.setSlotScope(slotScope);
            mbodyCode.addAll(0,toInsList(d.toSourceIgnoreReturnValue(localData,this)));
          }
        }
      }
      List<AVM2Instruction> acts=new ArrayList<>();
      acts.add(ins(AVM2Instructions.NewActivation));
      acts.add(ins(AVM2Instructions.Dup));
      acts.add(AssignableAVM2Item.generateSetLoc(localData.activationReg));
      acts.add(ins(AVM2Instructions.PushScope));
      mbodyCode.addAll(0,acts);
    }
    if (constructor) {
      int parentConstMinAC=0;
      AbcIndexing.ClassIndex ci=abcIndex.findClass(new TypeItem(superType));
      if (ci != null) {
        MethodInfo pmi=ci.abc.method_info.get(ci.abc.instance_info.get(ci.index).iinit_index);
        parentConstMinAC=pmi.param_types.length;
        if (pmi.flagHas_optional()) {
          parentConstMinAC-=pmi.optional.length;
        }
      }
      int ac=-1;
      for (      AVM2Instruction ins : mbodyCode) {
        if (ins.definition instanceof ConstructSuperIns) {
          ac=ins.operands[0];
          if (parentConstMinAC > ac) {
            throw new CompilationException("String_Node_Str",line);
          }
        }
      }
      if (ac == -1) {
        if (parentConstMinAC == 0) {
          mbodyCode.add(0,new AVM2Instruction(0,AVM2Instructions.GetLocal0,null));
          mbodyCode.add(1,new AVM2Instruction(0,AVM2Instructions.ConstructSuper,new int[]{0}));
        }
 else {
          throw new CompilationException("String_Node_Str",line);
        }
      }
    }
    if (!subMethod) {
      mbodyCode.add(0,new AVM2Instruction(0,AVM2Instructions.GetLocal0,null));
      mbodyCode.add(1,new AVM2Instruction(0,AVM2Instructions.PushScope,null));
    }
    boolean addRet=false;
    if (!mbodyCode.isEmpty()) {
      InstructionDefinition lastDef=mbodyCode.get(mbodyCode.size() - 1).definition;
      if (!((lastDef instanceof ReturnVoidIns) || (lastDef instanceof ReturnValueIns))) {
        addRet=true;
      }
    }
 else {
      addRet=true;
    }
    if (addRet) {
      if (retType.toString().equals("String_Node_Str") || retType.toString().equals("String_Node_Str") || constructor) {
        mbodyCode.add(new AVM2Instruction(0,AVM2Instructions.ReturnVoid,null));
      }
 else {
        mbodyCode.add(new AVM2Instruction(0,AVM2Instructions.PushUndefined,null));
        mbodyCode.add(new AVM2Instruction(0,AVM2Instructions.ReturnValue,null));
      }
    }
    mbody.exceptions=localData.exceptions.toArray(new ABCException[localData.exceptions.size()]);
    int offset=0;
    for (int i=0; i < mbodyCode.size(); i++) {
      AVM2Instruction ins=mbodyCode.get(i);
      if (ins instanceof ExceptionMarkAVM2Instruction) {
        ExceptionMarkAVM2Instruction m=(ExceptionMarkAVM2Instruction)ins;
switch (m.markType) {
case MARK_E_START:
          mbody.exceptions[m.exceptionId].start=offset;
        break;
case MARK_E_END:
      mbody.exceptions[m.exceptionId].end=offset;
    break;
case MARK_E_TARGET:
  mbody.exceptions[m.exceptionId].target=offset;
break;
}
mbodyCode.remove(i);
i--;
continue;
}
offset+=ins.getBytesLength();
}
mbody.markOffsets();
mbody.autoFillStats(abcIndex.getSelectedAbc(),initScope,className != null);
abcIndex.getSelectedAbc().addMethodBody(mbody);
mindex=mbody.method_info;
}
 else {
mindex=abcIndex.getSelectedAbc().addMethodInfo(mi);
}
return mindex;
}