@Override
public Result<IValue> fieldSelect(Field[] selectedFields) {
int nFields = selectedFields.length;
int fieldIndices[] = new int[nFields];
Type baseType = this.getType();
for (int i = 0; i < nFields; i++) {
Field f = selectedFields[i];
if (f.isIndex()) {
fieldIndices[i] = ((IInteger) f.getFieldIndex()
.interpret(this.ctx.getEvaluator()).getValue()).intValue();
} else {
String fieldName = org.rascalmpl.interpreter.utils.Names
.name(f.getFieldName());
try {
fieldIndices[i] = baseType.getFieldIndex(fieldName);
} catch (UndeclaredFieldException e) {
throw new UndeclaredField(fieldName, baseType,
ctx.getCurrentAST());
}
}
if (fieldIndices[i] < 0 || fieldIndices[i] > baseType.getArity()) {
throw org.rascalmpl.interpreter.utils.RuntimeExceptionFactory
.indexOutOfBounds(ValueFactoryFactory.getValueFactory().integer(fieldIndices[i]),
ctx.getCurrentAST(), ctx.getStackTrace());
}
}