for(int i = 0; i < patternSize; i += delta){
IMatchingResult child = patternChildren.get(i);
isListVar[i] = false;
plusList[i] = false;
isBindingVar[i] = false;
Environment env = ctx.getCurrentEnvt();
if (child instanceof TypedMultiVariablePattern) {
TypedMultiVariablePattern tmvVar = (TypedMultiVariablePattern) child;
Type tmvType = tmvVar.getType(env, null);
String name = tmvVar.getName();
varName[i] = name;
isListVar[i] = true;
listVarOccurrences[i] = 1;
++nListVar;
if(!tmvVar.isAnonymous() && allVars.contains(name)) {
throw new RedeclaredVariable(name, getAST());
} else if(tmvType.comparable(listSubject.getType().getElementType())
|| (tmvVar.bindingInstance() && tmvType.comparable(listSubject.getType()))) {
tmvVar.convertToListType();
if (!tmvVar.isAnonymous()) {
allVars.add(name);
}
isBindingVar[i] = true;
} else {
hasNext = false;
return;
}
}
else if(child instanceof MultiVariablePattern){
MultiVariablePattern multiVar = (MultiVariablePattern) child;
String name = multiVar.getName();
varName[i] = name;
isListVar[i] = true;
nListVar++;
if(!multiVar.isAnonymous() && allVars.contains(name)){
isBindingVar[i] = false;
} else if(multiVar.isAnonymous()){
isBindingVar[i] = true;
} else {
allVars.add(name);
Result<IValue> varRes = env.getVariable(name);
if (varRes == null || multiVar.bindingInstance()) {
isBindingVar[i] = true;
} else {
isBindingVar[i] = false;
Type varType = varRes.getType();
if (isAnyListType(varType)){
if (!varType.comparable(listSubjectType)) {
hasNext = false;
return;
}
} else {
if(!(varType instanceof NonTerminalType) && !(varType.comparable(staticListSubjectElementType))) {
hasNext = false;
return;
}
}
}
}
}
else if (child instanceof ConcreteListVariablePattern) {
ConcreteListVariablePattern listVar = (ConcreteListVariablePattern) child;
String name = listVar.getName();
varName[i] = name;
isListVar[i] = true;
if (!listVar.isAnonymous()) {
allVars.add(name);
}
plusList[i] = listVar.isPlusList();
isBindingVar[i] = true;
listVarOccurrences[i] = 1;
nListVar++;
}
else if(child instanceof QualifiedNamePattern){
QualifiedNamePattern qualName = (QualifiedNamePattern) child;
String name = qualName.getName();
varName[i] = name;
if(!qualName.isAnonymous() && allVars.contains(name)){
/*
* A variable that was declared earlier in the pattern
*/
isListVar[i] = true;
nListVar++;
listVarOccurrences[i]++;
} else if(qualName.isAnonymous()){
/*
* Nothing to do
*/
} else {
Result<IValue> varRes = env.getVariable(name);
if(varRes == null || qualName.bindingInstance()){
// A completely new non-list variable, nothing to do
} else {
Type varType = varRes.getType();