<?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>5810</bug_id>
          
          <creation_ts>2008-06-26 13:19:53 +0000</creation_ts>
          <short_desc>[XQuery] reasoning about fn:error()</short_desc>
          <delta_ts>2009-03-07 06:53:43 +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>XQuery 1.0</component>
          <version>Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</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="Tim Mills">tim</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>jim.melton</cc>
    
    <cc>jmdyck</cc>
    
    <cc>mike</cc>
          
          <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>20924</commentid>
    <comment_count>0</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2008-06-26 13:19:53 +0000</bug_when>
    <thetext>There has been a long discussion in Bug 5795 about fn:error().

Many implementations will happily use lazy evaluation to avoid an error in the query:

(1, fn:error())[1]

Is it also permissible to avoid an error here:

(fn:error(), 1)[2]

? 

Since fn:error has type none, whose quantifier is 1, is it conformant for

count(fn:error())

to return 1?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20932</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2008-06-26 14:26:18 +0000</bug_when>
    <thetext>Since fn:error has type none, whose quantifier is 1, is it conformant for

count(fn:error())

to return 1?

It seems to me that you&apos;re inferring that fn:error() will return a sequence of length one, which is incorrect - it won&apos;t return at all.

Is it also permissible to avoid an error here:

(fn:error(), 1)[2]

That seems to make the same inference that fn:error() will return a singleton - which it won&apos;t.

But of course with

(fn:error(), 1)[last()]

returning 1 would be fine.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20935</commentid>
    <comment_count>2</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2008-06-26 14:34:15 +0000</bug_when>
    <thetext>&gt; It seems to me that you&apos;re inferring that fn:error() will return a sequence of
&gt; length one, which is incorrect - it won&apos;t return at all.

To be precise, I&apos;m inferring that _if it were_ to return a result, it would return a sequence of length one (base on the quantifier). 

Consider instead:

declare function local:mystery() as xs:integer
{
  fn:error()
};

count(local:mystery)




</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20937</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2008-06-26 14:56:15 +0000</bug_when>
    <thetext>&gt;I&apos;m inferring that _if it were_ to return a result, it would return a sequence of length one

Hypotheticals are dangerous. If error() were to return a result, pigs would fly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20939</commentid>
    <comment_count>4</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2008-06-26 15:01:01 +0000</bug_when>
    <thetext>&gt; Hypotheticals are dangerous. If error() were to return a result, pigs would
fly.

:)

Incidentally, according to FS normalization rules:

(fn:error(), 1)[last()]

last() gets replaced with variable $fs:last, defined as:

fn:count((fn:error(), 1) ) 

...so were back to the counting question.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20943</commentid>
    <comment_count>5</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2008-06-26 15:25:47 +0000</bug_when>
    <thetext>Another thing to consider is that type &apos;none&apos; gets quite easily &apos;lost&apos; during type checking.

e.g.

count( if ( ... ) then 1 else fn:error() )


The type of:

if ( ... ) then 1 else fn:error() 

is xs:integer | none = xs:integer.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20965</commentid>
    <comment_count>6</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2008-06-27 16:13:32 +0000</bug_when>
    <thetext>According to the typing rules in Bug 4841

fs:item-at( fn:error(), Expr) is empty-sequence.

as produced by

(fn:error()[1])

Is this correct/desirable?  Does this match the intended evaluation semantics?

This may also affect fn:subsequence.

Perhaps these should be defined to be of type none, i.e. erroneous?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20971</commentid>
    <comment_count>7</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2008-06-27 20:22:33 +0000</bug_when>
    <thetext>(In reply to comment #6)
&gt; According to the typing rules in Bug 4841
&gt; 
&gt; fs:item-at( fn:error(), Expr) is empty-sequence.

That could be misread as a statement about the value of the expression, so let me state more precisely that, according to those rules, the static type of
    fs:item-at( fn:error(), Expr)
is the type &apos;empty&apos;. Which implies that, if evaluated, the expression will either raise a (non-type) error, or return the empty sequence. This is consistent with the dynamic semantics: a strict evaluation will always raise err:FOER0000. (But an implementation is allowed to rewrite the expression to return the empty sequence, according to the XQuery rewrite rules.)

&gt; Perhaps these should be defined to be of type none, i.e. erroneous?

Perhaps.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20984</commentid>
    <comment_count>8</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2008-06-30 08:03:59 +0000</bug_when>
    <thetext>Thanks Michael (Dyck).  Do you have an opinion on whether 

count(fn:error())

is 1, and whether (more generally) it is permitted to count a function whose argument has quantifier 1 without evaluating it?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20990</commentid>
    <comment_count>9</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2008-06-30 20:13:51 +0000</bug_when>
    <thetext>[Personal response]

(In reply to comment #8)
&gt; Do you have an opinion on whether 
&gt; 
&gt; count(fn:error())
&gt; 
&gt; is 1,

Under a strict evaluation, the expression always raises a dynamic error, so the question is more like &quot;Is an implementation allowed to rewrite the expression into one that always returns 1?&quot;. I believe the answer is yes, but really it&apos;s allowed to rewrite it into *anything*. That is, when the original expression raises an error, the XQuery rewrite rules don&apos;t constrain the value/error resulting from the rewritten expression. (The classic example being an implementation that returns 42 for the expression 1 div 0. It&apos;s allowed, but frowned upon.)

If the question is whether it&apos;s a &quot;reasonable&quot; or &quot;defensible&quot; rewrite, I&apos;m not sure. Although FS 8.4 says
    quantifier(none) = 1
it&apos;s doing so in the context of defining a particular pseudo-function for use in particular rules. Applying it elsewhere isn&apos;t guaranteed to give meaningful results. (Note that FS 8.4 also says
    quantifier(empty) = ?
which could lead to some bad inferences if mis-applied.)

&gt; and whether (more generally) it is permitted to count a function whose
&gt; argument has quantifier 1 without evaluating it?

If an implementation can prove (via quantifiers or whatever) that a particular call to fn:count() would, if evaluated, either raise an error or return 1, then I believe it is permitted (among other things) to yield 1 for that expression in all cases.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>24092</commentid>
    <comment_count>10</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2009-03-07 06:53:43 +0000</bug_when>
    <thetext>At their joint meeting last week, the Working Groups endorsed my remarks in
comment #9 and directed me to close this issue as resolved-WONTFIX.

If you accept this resolution, please mark the issue CLOSED.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>