<?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>15791</bug_id>
          
          <creation_ts>2012-01-30 12:05:34 +0000</creation_ts>
          <short_desc>[XQ30] XQST0054</short_desc>
          <delta_ts>2012-07-24 14:56:26 +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 3.0</component>
          <version>Member-only Editors Drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</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>
          
          <blocked>17272</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Tim Mills">tim</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>john.snelson</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>63325</commentid>
    <comment_count>0</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2012-01-30 12:05:34 +0000</bug_when>
    <thetext>In XQuery 3.0:

&quot;If the initializer of a variable V depends on V, a static error is raised [err:XQST0054]&quot;

I believe that the existance of fn:function-lookup may mean it is possible to construct a query in which a variable depends on itself, but that this cannot be determined statically.

Suppose the existance of a document &apos;some.xml&apos; with root element functionQName of type xs:QName with value &apos;local:return-v&apos;.  The following query shows how the initializer of $v might dynamically depend on $v.

declare variable $v := function-lookup(doc(&apos;some.xml&apos;)/functionQName, 0)();

declare function local:return-v()
{
  $v
};

$v

I suggest making this error a dynamic error, as it is in XSLT:

[Definition: A circularity is said to exist if a construct such as a global variable ... is defined in terms of itself. ... ]

[ERR XTDE0640] In general, a circularity in a stylesheet is a non-recoverable dynamic error. However, as with all other dynamic errors, an implementation will signal the error only if it actually executes the instructions and expressions that participate in the circularity. Because different implementations may optimize the execution of a stylesheet in different ways, it is implementation-dependent whether a particular circularity will actually be signaled.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63763</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2012-02-06 17:03:01 +0000</bug_when>
    <thetext>I have created test case function-lookup-013 based on this scenario (with a provisional outcome)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63841</commentid>
    <comment_count>2</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2012-02-07 15:12:29 +0000</bug_when>
    <thetext>Thatnks for adding the test.

However, it needs to be marked as XQ30+ only, as it contains an XQuery prolog.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63845</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2012-02-07 15:27:25 +0000</bug_when>
    <thetext>Dependency added as suggested.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64076</commentid>
    <comment_count>4</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2012-02-14 12:13:25 +0000</bug_when>
    <thetext>In the XQuery specification, I think the simplest approach is to add the following text:

If a global variable directly or indirectly relies on a dynamic
function call which at runtime turns out to directly or indirectly
rely on the global variable itself, an error is raised [err:TBD]

Are there other cases that we need to handle? If so, let&apos;s enumerate them.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64077</commentid>
    <comment_count>5</comment_count>
    <who name="John Snelson">john.snelson</who>
    <bug_when>2012-02-14 12:22:47 +0000</bug_when>
    <thetext>The phrase &quot;directly or indirectly relies on&quot; is not defined adequately to handle this case.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64299</commentid>
    <comment_count>6</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2012-02-20 11:44:55 +0000</bug_when>
    <thetext>Here&apos;s another example, but this time for XQST0107.

declare variable $n external := xs:QName(&apos;local:return-p&apos;);
declare variable $v := function-lookup($n, 0)();
declare function local:return-p() {$p};
declare variable $p external := fn:position();
declare context item := $v

.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64695</commentid>
    <comment_count>7</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2012-02-28 19:58:15 +0000</bug_when>
    <thetext>Here&apos;s a further example which I don&apos;t think should cause an error.

declare variable $n external := fn:QName(&quot;local:f&quot;);

declare variable $v := fn:function-lookup($n)(1);

declare function local:f($arg)
{
  If ($arg = 1)
  then $arg
  else $v 
};

$v</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68013</commentid>
    <comment_count>8</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2012-05-22 16:44:47 +0000</bug_when>
    <thetext>This may be resolved by the following proposal, which was adopted today:
https://lists.w3.org/Archives/Member/w3c-xsl-query/2012May/0118.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68867</commentid>
    <comment_count>9</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2012-06-07 22:28:29 +0000</bug_when>
    <thetext>(In reply to comment #8)
&gt; This may be resolved by the following proposal, which was adopted today:
&gt; https://lists.w3.org/Archives/Member/w3c-xsl-query/2012May/0118.html

Tim - do you believe that the proposal resolves this bug?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68874</commentid>
    <comment_count>10</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2012-06-08 14:50:40 +0000</bug_when>
    <thetext>Ghislain followed that up with a later message which covered XQST0107.

https://lists.w3.org/Archives/Member/w3c-xsl-query/2012May/0165.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>71387</commentid>
    <comment_count>11</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2012-07-24 14:56:26 +0000</bug_when>
    <thetext>(In reply to comment #10)
&gt; Ghislain followed that up with a later message which covered XQST0107.
&gt; 
&gt; https://lists.w3.org/Archives/Member/w3c-xsl-query/2012May/0165.html

This was adopted. We believe that this issue is now fixed.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>