<?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>30259</bug_id>
          
          <creation_ts>2018-05-31 19:26:57 +0000</creation_ts>
          <short_desc>[FO31] Normative function implementation given for fn:sum#2 seems to be at odds with the text</short_desc>
          <delta_ts>2018-05-31 20:31:12 +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>Functions and Operators 3.1</component>
          <version>Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></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="Abel Braaksma">abel.online</reporter>
          <assigned_to name="Michael Kay">mike</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>129275</commentid>
    <comment_count>0</comment_count>
    <who name="Abel Braaksma">abel.online</who>
    <bug_when>2018-05-31 19:26:57 +0000</bug_when>
    <thetext>For the two-argument function the spec gives the following implementation (and this seems normative)

    if (fn:count($c) eq 0) then
        $zero
    else if (fn:count($c) eq 1) then
        $c[1]
    else
        $c[1] + fn:sum(subsequence($c, 2))

However, that means that sum(&apos;a&apos;, 0) would not raise an error. And since fn:sum#1 is also defined to mean sum($arg, 0), sum(&apos;a&apos;) wouldn&apos;t raise an error either.

But the text gives:

&quot;In addition, the type must support addition&quot;

And this is confirmed in the explanation of FORG0006. However, I am wondering why then wouldn&apos;t the above function be defined as:

    if (fn:count($c) eq 0) then
        $zero
    else
        fn:sum($c)

Which then leads me to the assumption that the &apos;else if&apos; is deliberate and trumps the rule of having to raise FORG0006, but I cannot say I am entirely sure of it. Could this be clarified in a (possible) update to the erratum?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>129276</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2018-05-31 20:31:12 +0000</bug_when>
    <thetext>I think the intended reading is that all the rules must be satisfied. That is,

(a) All items in $arg must be numeric or derived from a single base type.

and

(b) The result of the function, using the second signature, is the result of the expression:

must both be satisfied.

Note that the supplied implementation also does not incorporate the rule that the items can be processed in any order (which could affect overflow or underflow behavior).</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>