}   if (Type.subTypeOf(type.getPrimaryType(), Type.ATOMIC)) { if(!Type.subTypeOf(returnType, Type.ATOMIC)) expr = new Atomize(context, expr); if (!(type.getPrimaryType() == Type.ATOMIC)) expr = new UntypedValueCheck(context, type.getPrimaryType(), expr, new Error(Error.FUNC_PARAM_TYPE, String.valueOf(argPosition), mySignature)); returnType = expr.returnsType();
if (Type.subTypeOf(type.getPrimaryType(), Type.ATOMIC)) { if(!Type.subTypeOf(returnType, Type.ATOMIC)) expr = new Atomize(context, expr); if (!(type.getPrimaryType() == Type.ATOMIC)) expr = new UntypedValueCheck(context, type.getPrimaryType(), expr, new Error(Error.FUNC_PARAM_TYPE, String.valueOf(argPosition), mySignature)); returnType = expr.returnsType(); }  } else {  if (Type.subTypeOf(type.getPrimaryType(), Type.ATOMIC)) { if(!Type.subTypeOf(returnType, Type.ATOMIC)) expr = new Atomize(context, expr);  expr = new UntypedValueCheck(context, type.getPrimaryType(), expr, new Error(Error.FUNC_PARAM_TYPE, String.valueOf(argPosition), mySignature)); returnType = expr.returnsType(); }
	protected Expression checkArgument(Expression expr, SequenceType type, int argPosition)		throws XPathException {		if (type == null)			return expr;		// check cardinality if expected cardinality is not zero or more		boolean cardinalityMatches =			type.getCardinality() == Cardinality.ZERO_OR_MORE;		if (!cardinalityMatches) {			cardinalityMatches =				(expr.getCardinality() | type.getCardinality())					== type.getCardinality();			if (!cardinalityMatches) {				if(expr.getCardinality() == Cardinality.ZERO				&& (type.getCardinality() & Cardinality.ZERO) == 0)				    throw new XPathException(getASTNode(), 				            Messages.getMessage(Error.FUNC_EMPTY_SEQ_DISALLOWED, 				                    new Integer(argPosition), ExpressionDumper.dump(expr)));			}		}		expr =			new DynamicCardinalityCheck(				context,				type.getCardinality(),				expr, new Error(Error.FUNC_PARAM_CARDINALITY, String.valueOf(argPosition), mySignature));		// check return type if both types are not Type.ITEM		int returnType = expr.returnsType();        if (returnType == Type.ANY_TYPE || returnType == Type.EMPTY)            returnType = Type.ITEM;        		boolean typeMatches = type.getPrimaryType() == Type.ITEM;		typeMatches = Type.subTypeOf(returnType, type.getPrimaryType());		if (typeMatches && cardinalityMatches) {			if(type.getNodeName() != null)				expr = new DynamicNameCheck(context, 						new NameTest(type.getPrimaryType(), type.getNodeName()), expr);			return expr;		}				if (context.isBackwardsCompatible()) {			if (Type.subTypeOf(type.getPrimaryType(), Type.STRING)) {				if (!Type.subTypeOf(returnType, Type.ATOMIC)) {					expr = new Atomize(context, expr);					returnType = Type.ATOMIC;				}				expr = new AtomicToString(context, expr);				returnType = Type.STRING;			} else if (type.getPrimaryType() == Type.NUMBER					|| Type.subTypeOf(type.getPrimaryType(), Type.DOUBLE)) {				if (!Type.subTypeOf(returnType, Type.ATOMIC)) {					expr = new Atomize(context, expr);					returnType = Type.ATOMIC;				}				expr =					new UntypedValueCheck(context, type.getPrimaryType(), expr,                             new Error(Error.FUNC_PARAM_TYPE, String.valueOf(argPosition), mySignature));				returnType = type.getPrimaryType();			}		}		// if the required type is an atomic type, convert the argument to an atomic 		if (Type.subTypeOf(type.getPrimaryType(), Type.ATOMIC)) {			if(!Type.subTypeOf(returnType, Type.ATOMIC))				expr = new Atomize(context, expr);			if (!(type.getPrimaryType() == Type.ATOMIC))				expr =					new UntypedValueCheck(context, type.getPrimaryType(), expr,                             new Error(Error.FUNC_PARAM_TYPE, String.valueOf(argPosition), mySignature));			returnType = expr.returnsType();		}		if (returnType != Type.ITEM && !Type.subTypeOf(returnType, type.getPrimaryType())) {			if ((!Type.subTypeOf(type.getPrimaryType(), returnType))) {                LOG.debug(ExpressionDumper.dump(expr));                throw new XPathException(getASTNode(),                        Messages.getMessage(Error.FUNC_PARAM_TYPE_STATIC,                                 String.valueOf(argPosition), mySignature,                                type.toString(), Type.getTypeName(returnType)));            }		}		if (!typeMatches) {			if(type.getNodeName() != null)				expr = new DynamicNameCheck(context, 						new NameTest(type.getPrimaryType(), type.getNodeName()), expr);			else				expr = new DynamicTypeCheck(context, type.getPrimaryType(), expr);		}		return expr;	}