<?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>30313</bug_id>
          
          <creation_ts>2018-11-03 23:07:56 +0000</creation_ts>
          <short_desc>[xslt30] Overriding variables must have &quot;identical declared type&quot;; what if they have no declared type?</short_desc>
          <delta_ts>2019-02-28 15:31:44 +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>XSLT 3.0</component>
          <version>Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>REOPENED</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="Michael Kay">mike</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          <cc>abel.online</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>129376</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2018-11-03 23:07:56 +0000</bug_when>
    <thetext>In §3.5.3.3 it is stated that an when one global variables overrides another, &quot;Their declared types [must be] identical.&quot;

It&apos;s not clear what this means when there is no explicit declared type.

The difficulty exists particularly because the &quot;as&quot; attribute does not have a simple lexical default.

Consider

&lt;xsl:variable name=&quot;x&quot; select=&quot;23&quot;/&gt;

versus

&lt;xsl;variable name=&quot;x&quot;&gt;23&lt;/xsl:variable&gt;

I suggest the interpretation:

Their declared types [must be] identical. The declared type of a variable for this purpose is the &quot;SequenceType&quot; appearing in the &quot;as&quot; attribute, or &quot;item()*&quot; in the absence of the &quot;as&quot; attribute.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>129384</commentid>
    <comment_count>1</comment_count>
    <who name="Abel Braaksma">abel.online</who>
    <bug_when>2018-11-16 15:46:14 +0000</bug_when>
    <thetext>We currently allow overriding a variable if their types, implicitly or explicitly, are identical. 

I think that if we default it to item()*, this can be problematic for implicit defaults like document() or xs:string. In your example it is statically known that the type of the second $x is document() and the type of the first $x is xs:integer.

However, the static type may not be definitively known. The select-expression could call fn:collection, which can return any type and I&apos;m sure there are other possibilities. Though statically, these would simply default to item()*.

I&apos;m not sure what the best cause of action is. One alternative way of reading &quot;the declared types must be identical&quot; is that it seems to implicitly require a declared type on variables. In the absence thereof (i.e., no as-clause), you cannot override the xsl:variable. The logic being: &quot;when the type is not declared, its type is unknown and cannot always be assessed statically to be equal&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>129385</commentid>
    <comment_count>2</comment_count>
    <who name="Abel Braaksma">abel.online</who>
    <bug_when>2018-11-16 15:59:32 +0000</bug_when>
    <thetext>Hmm, one complicating factor is that the large example on binding components (3.5.3.5 Binding References to Components) exclusively uses variables that have no as-clause. Having that example suggests that overriding without as-clause is valid, but the prose in that section do not mention the type-identicality.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>129501</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2019-02-15 10:50:14 +0000</bug_when>
    <thetext>I propose that after &quot;Their declared types are identical.&quot; we add &quot;The declared type is the type appearing in the &apos;as&apos; attribute if present; in the absence of an &apos;as&apos; attribute, the declared type is &apos;item()*&apos; if a &apos;select&apos; attribute is present, or &apos;document-node()&apos; otherwise.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>129502</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2019-02-15 11:00:35 +0000</bug_when>
    <thetext>Or more precisely:

For this purpose, the declared type is the first of the following that applies:
				
* If there is an &lt;code&gt;as&lt;/code&gt; attribute, then the type defined by that attribute.

* If there is a &lt;code&gt;select&lt;/code&gt; attribute, then &lt;code&gt;item()*&lt;/code&gt;.

* If there is a non-empty sequence constructor, then &lt;code&gt;document-node()&lt;/code&gt;.

* Otherwise, &lt;code&gt;xs:string&lt;/code&gt;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>129521</commentid>
    <comment_count>5</comment_count>
    <who name="Abel Braaksma">abel.online</who>
    <bug_when>2019-02-19 20:39:21 +0000</bug_when>
    <thetext>Since this only pertains to xsl:variable and not xsl:param (which tends to be more malleable), I think it is a fair solution while still allowing processors to optimize for the (rather complex) default variable types.

For reference, a draft proposal erratum was published on 13 Feb 2019, E35, see:
https://htmlpreview.github.io/?https://github.com/w3c/qtspecs/blob/master/errata/xslt-30/html/xslt-30-errata.html#E35</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>129587</commentid>
    <comment_count>6</comment_count>
    <who name="Abel Braaksma">abel.online</who>
    <bug_when>2019-02-28 15:31:44 +0000</bug_when>
    <thetext>Reopening as I think we forgot one tiny little bit: existing examples in the spec.

I propose we change the existing examples where it is applicable. They are not necessarily wrong but as written they can lead to confusion, esp. in light of overriding. I think we only need to address the examples overriding is an option.

Luckily there&apos;s only a handful:

B.2 Stylesheet JSON
- variable $quot is private, leave as is

3.5.3.5 Binding References to Components
- variable $C has implicit type xs:integer, would benefit from as=&quot;xs:integer&quot; for clarity
- example with xsl:override on $C, same, should have as=&quot;xs:integer&quot; for clarity
- others are private/final, cannot be overridden

3.5.3.6 Dynamic References to Components
- in the Note, variable $get-order. Should have an as-clause as otherwise the type is item()* and that is not the intend here and can lead to errors.

3.5.7 Worked Example of a Library Package
- nothing to do, all xsl:variable have a type



Other variables do not appear under xsl:package and are therefore not open to misinterpretation.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>