<?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>14330</bug_id>
          
          <creation_ts>2011-09-29 01:50:24 +0000</creation_ts>
          <short_desc>[XQuery30] technical: 3.1.6 Literal Function Items: static context</short_desc>
          <delta_ts>2011-11-18 06:48:35 +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>Working drafts</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</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 Dyck">jmdyck</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>jim.melton</cc>
    
    <cc>john.snelson</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>57497</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2011-09-29 01:50:24 +0000</bug_when>
    <thetext>3.1.6 Literal Function Items says:

&quot;The static context for evaluation of the function item [created by a literal function item expression] is inherited from the location of the literal function item expression...&quot;

First, it&apos;s incorrect to talk about &quot;the evaluation of a function item&quot;, because a function item is already a value. Instead, you can *invoke* a function item, which then typically involves evaluation of the expression that is the function item&apos;s implementation.

So, assuming that it&apos;s the latter expression whose static context is the subject of the quoted sentence, I believe the statement is incorrect. Consider:

  declare variable $v as xs:integer := 7;
  declare function f() { $v+1 };
  let $v as xs:string := &quot;foo&quot;
  let $fi := f#1
  return $fi()

I think the result should be 8, but I think the quoted statement says that the result is a type error. At the location of the literal function item expression f#1, the static context says variable $v is of type xs:string. If you try to evaluate the function body $v+1 in such a context, you&apos;ll get a type error. (Or perhaps the result is undefined, if the value for $v is inconsistent with xs:string.)

To fix, I think we should simply delete the quoted sentence. (The new function item&apos;s implementation is that of the referenced function, and that implementation&apos;s static context [if it has one] is whatever it is.)

The sentence goes on to point out that the static type of the context item is initially undefined. This is worth saying, but not here. Instead, it belongs where function bodies are introduced: 3.1.7 &quot;Inline Functions&quot; already says it; 4.18 &quot;Function Declarations&quot; should add it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>59324</commentid>
    <comment_count>1</comment_count>
    <who name="John Snelson">john.snelson</who>
    <bug_when>2011-10-31 22:12:09 +0000</bug_when>
    <thetext>I think the quoted text is trying to understand what the behaviour of static-base-uri#0 is supposed to be, as well as (for instance) the static context available to an external function - or anything else that might access the static context, without itself being defined in a module.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>59326</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2011-10-31 22:13:48 +0000</bug_when>
    <thetext>(Oops, I should have said f#0, not f#1.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60053</commentid>
    <comment_count>3</comment_count>
    <who name="Jim Melton">jim.melton</who>
    <bug_when>2011-11-15 17:29:54 +0000</bug_when>
    <thetext>(I changed the Component to XPath 3.0 because this bug affects XPath as well as XQuery.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60056</commentid>
    <comment_count>4</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2011-11-15 20:18:17 +0000</bug_when>
    <thetext>We have decided to resolve this by not allowing function items to refer to context-dependent built-in functions. 

Function items can refer to context-independent built-in functions, but not context-independent built-in functions.

You can create an inline function to wrap a context-dependent built-in function.

We will add a note, in the STATUS section, saying that we are considering removing this restriction for some or all context-dependent functions after the Last Call period.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60057</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2011-11-15 20:49:55 +0000</bug_when>
    <thetext>Note that the decision described in comment #4 doesn&apos;t directly address the original issue (the example in comment #0 doesn&apos;t involve built-in functions); rather, it addresses the question that (John Snelson thought) the original text was meant to answer. That is, I believe comment #4 describes a *replacement* for the sentence I quoted in comment #0. If that&apos;s the case, then it does provide a fix for this issue.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60058</commentid>
    <comment_count>6</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2011-11-15 20:51:43 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; I believe comment #4 describes a *replacement*
&gt; for the sentence I quoted in comment #0. If that&apos;s the case, then it does
&gt; provide a fix for this issue.

That is how I understood our decision. I believe the sentence you quoted can be deleted.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60135</commentid>
    <comment_count>7</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2011-11-18 06:48:35 +0000</bug_when>
    <thetext>In the editor&apos;s draft of the XQuery/XPath spec, I have carried out my suggestions in comment #0, and (with respect to comment #4) changed the triggers for err:XPST0112 from &quot;focus-dependent&quot; to &quot;context-dependent built-in&quot;.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>