#351 Numeric promotion causing spurious cardinality error

v8.4
closed
nobody
5
2012-10-08
2005-04-21
Michael Kay
No

When an expression of one numeric type is used in a
context where a different numeric type is expected,
such that numeric promotion gets invoked (for example,
from integer to double), a spurious type error may be
reported indicating that the cardinality of the
supplied value is incorrect. This only happens where
the supplied value can be evaluated at compile time.

Patch:

(a) in net.sf.saxon.expr.NumericPromoter, line 37,
change the simplify() method to read:

 public Expression simplify(StaticContext env)

throws XPathException {
operand = operand.simplify(env);
if (operand instanceof AtomicValue) {
return promote(((AtomicValue)operand), null);
} else if (operand instanceof Value) {
return
SequenceExtent.makeSequenceExtent(iterate(null)).reduce();
}
return this;
}

(b) in net.sf.saxon.expr.TypeChecker, line 221, after
the line

suppliedItemType = (rt == StandardNames.XS_DOUBLE ?
Type.DOUBLE_TYPE : Type.FLOAT_TYPE);

add the line:

                    suppliedCard = -1;

Michael Kay

Discussion