Project

Profile

Help

Revision 8e51c479

Added by Michael Kay almost 13 years ago

Fix bug 2509532 - promotion from double to float

View differences:

latest9.1/bj/net/sf/saxon/expr/NumericPromoter.java
117 117
            err.setLocator(this);
118 118
            throw err;
119 119
        }
120
        if (requiredType.equals(BuiltInAtomicType.FLOAT) && value instanceof DoubleValue) {
121
            XPathException err = new XPathException(
122
                    "Cannot promote from xs:double to xs:float", "XPTY0004", context);
123
            err.setLocator(this);
124
            throw err;
125
        }
120 126
        return value.convert(requiredType, true, context).asAtomic();
121 127
    }
122 128

  
latest9.1/bj/net/sf/saxon/expr/TypeChecker.java
226 226
                // Rule 3a: numeric promotion decimal -> float -> double
227 227

  
228 228
                int rt = ((AtomicType)reqItemType).getFingerprint();
229
                if (rt == StandardNames.XS_DOUBLE || rt == StandardNames.XS_FLOAT) {
230
                    if (th.relationship(suppliedItemType, BuiltInAtomicType.NUMERIC) != TypeHierarchy.DISJOINT) {
231
                        Expression cexp = new NumericPromoter(exp, (BuiltInAtomicType)reqItemType.getPrimitiveItemType());
232
                        ExpressionTool.copyLocationInfo(exp, cexp);
233
                        exp = cexp;
234
                        try {
235
                            exp = visitor.typeCheck(visitor.simplify(exp), AnyItemType.getInstance());
236
                        } catch (XPathException err) {
237
                            err.maybeSetLocation(exp);
238
                            throw err.makeStatic();
239
                        }
240
                        suppliedItemType = (rt == StandardNames.XS_DOUBLE ? BuiltInAtomicType.DOUBLE : BuiltInAtomicType.FLOAT);
241
                        suppliedCard = -1;
229
                if ((rt == StandardNames.XS_DOUBLE &&
230
                            th.relationship(suppliedItemType, BuiltInAtomicType.NUMERIC) != TypeHierarchy.DISJOINT) ||
231
                        (rt == StandardNames.XS_FLOAT &&
232
                            th.relationship(suppliedItemType, BuiltInAtomicType.NUMERIC) != TypeHierarchy.DISJOINT) &&
233
                            !th.isSubType(suppliedItemType, BuiltInAtomicType.DOUBLE)) {
234
                    Expression cexp = new NumericPromoter(exp, (BuiltInAtomicType)reqItemType.getPrimitiveItemType());
235
                    ExpressionTool.copyLocationInfo(exp, cexp);
236
                    exp = cexp;
237
                    try {
238
                        exp = visitor.typeCheck(visitor.simplify(exp), AnyItemType.getInstance());
239
                    } catch (XPathException err) {
240
                        err.maybeSetLocation(exp);
241
                        throw err.makeStatic();
242 242
                    }
243
                    suppliedItemType = (rt == StandardNames.XS_DOUBLE ? BuiltInAtomicType.DOUBLE : BuiltInAtomicType.FLOAT);
244
                    suppliedCard = -1;
243 245
                }
244 246

  
245 247
                // Rule 3b: promotion from anyURI -> string

Also available in: Unified diff