throws XQueryException {
assert (argv != null);
assert (expectedArgType != null);
// If the function expects atomic parameters, then fn:data is called
// to obtain them.
final Type primeType = expectedArgType.prime();
if(primeType instanceof AtomicType) {
// Inserts conversions of function arguments that depend only on
// the expected SequenceType of the corresponding parameters.
if(expectedArgType instanceof SequenceType) {
expectedArgType = ((SequenceType) expectedArgType).prime();
}
if(!(expectedArgType instanceof AtomicType)) {
throw new TypeError("expectedArgType must be built-in atomic type, but was "
+ expectedArgType);
}
final AtomicType expected = (AtomicType) expectedArgType;
final ValueSequence res = new ValueSequence(dynEnv);
final IFocus<? extends Item> atomizedItor = argv.atomize(dynEnv).iterator();
for(Item it : atomizedItor) {
final Type actualType = it.getType();
// apply fs:ConvertSimpleOperand
if(actualType == UntypedAtomicType.UNTYPED_ATOMIC && expected.getTypeId() >= 0) {
final AtomicValue casted = ((AtomicValue) it).castAs(expected, dynEnv);
res.addItem(casted);
} else {