<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>4873</bug_id>
          
          <creation_ts>2007-07-21 21:42:16 +0000</creation_ts>
          <short_desc>[XPath] What errors are caught by Castable As?</short_desc>
          <delta_ts>2007-11-16 11:59:58 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XPath 2.0</component>
          <version>Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows XP</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Kay">mike</reporter>
          <assigned_to name="Don Chamberlin">chamberl</assigned_to>
          
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>15898</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2007-07-21 21:42:16 +0000</bug_when>
    <thetext>The purpose of the &quot;castable as&quot; operator is to catch casting errors. But it&apos;s not entirely clear from the spec what errors it catches. Clearly [&quot;a&quot; castable as xs:integer] returns false. I think it&apos;s also reasonably clear (well, at any rate it seems common-sense) that [(1 div 0) castable as xs:integer] doesn&apos;t return false, it throws an error: the failure is not in performing the cast, but in evaluating the operand of the cast.

Now consider [$x castable as xs:integer], where $x is an element with element-only content. Evaluating the expression causes $x to be atomized, and atomization fails for such an element. Has the failure occurred while evaluating the operand, or while testing castability?

The current text leaves this rather open. It uses the sentence &quot;The expression V castable as T returns true if the value V can be successfully cast into the target type T by using a cast expression&quot;. This doesn&apos;t stand up to scrutiny: one minute V is an expression, a moment later it is a value.

I suggest the wording: &quot;The expression E castable as T returns true if the result of evaluating E can be successfully cast into the target type T by using a cast expression. If evaluation of E fails with a dynamic error, the castable expression as a whole fails.&quot;

This wording would have the effect that an atomization failure would indeed produce a &quot;false&quot; result rather than an error, because atomization is done as part of the attempted cast operation, not as part of evaluating E.

(Aside: Given an arbitrary element, how do you test to see whether atomization will succeed before attempting it? Even if &quot;castable&quot; catches atomization errors, [$x castable as xs:string] doesn&apos;t do the trick, because it will return false not only for unatomizable elements, but also for elements whose atomized value is not a singleton....) 

Incidentally, there&apos;s another slightly unrigorous phrase in rule 1 of 3.10.2 Cast, where it says &quot;Atomization is performed on the input expression.&quot; It should really say &quot;Atomization is performed on the result of evaluating the input expression.&quot; - you can only atomize a value, not an expression.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>15979</commentid>
    <comment_count>1</comment_count>
    <who name="Don Chamberlin">chamberl</who>
    <bug_when>2007-07-31 17:48:55 +0000</bug_when>
    <thetext>On July 31, 2007, the XSLT and Query working groups reviewed this bug report and agreed to make the wording change suggested by Michael Kay.
--Don Chamberlin (for the joint working groups)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>17779</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2007-11-16 11:59:58 +0000</bug_when>
    <thetext>The agreed change will be implemented in erratum XP.E5 for XPath, and XQ.E5 for XQuery.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>