final Sequence funcSeq = functionExpr.eval(contextSequence, contextItem);
if (funcSeq.getCardinality() != Cardinality.EXACTLY_ONE)
{throw new XPathException(this, ErrorCodes.XPTY0004,
"Expected exactly one item for the function to be called, got " + funcSeq.getItemCount() +
". Expression: " + ExpressionDumper.dump(functionExpr));}
final Item item0 = funcSeq.itemAt(0);
if (!Type.subTypeOf(item0.getType(), Type.FUNCTION_REFERENCE))
{throw new XPathException(this, ErrorCodes.XPTY0004,
"Type error: expected function, got " + Type.getTypeName(item0.getType()));}
final FunctionReference ref = (FunctionReference)item0;
// if the call is a partial application, create a new function