<?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>1968</bug_id>
          
          <creation_ts>2005-09-03 12:17:30 +0000</creation_ts>
          <short_desc>typing for fn:subsequence() too strict</short_desc>
          <delta_ts>2005-09-08 16:46:06 +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>Formal Semantics 1.0</component>
          <version>Last Call drafts</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>1728</dup_id>
          
          <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="Jens Teubner">jens.teubner</reporter>
          <assigned_to name="Jerome Simeon">simeon</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>5691</commentid>
    <comment_count>0</comment_count>
    <who name="Jens Teubner">jens.teubner</who>
    <bug_when>2005-09-03 12:17:31 +0000</bug_when>
    <thetext>The XQuery Formal Semantics define a number of specific typing
rules for the built-in function fn:subsequence() in order to
reveal a static type as specific as possible.

Among others, the following rule is included in these specifics:

     statEnv |- Expr : Type       quantifier(Type) in {1, +}
 -------------------------------------------------------------
   statEnv |- fn:subsequence(Expr, $fs:last, 1) : prime(Type)

Note that in this inference rule, $fs:last is completely unrelated
to the expression Expr.  The current context is not necessarily
related to the argument of fn:subsequence().

In particular, the size of the current context set (and thus
$fs:last) may be larger than the size of Expr.  fn:subsequence()
returns the empty sequence if its start argument is greater than
the length of the sequence.  The avove typing rule, however, does
not include the empty sequence in the (static) return type of
fn:subsequence().  If the start argument is smaller than the
length of Expr, fn:subsequence() will return a sequence longer than
one.

Consider the following query (not really a sensible query, but it
demonstrates a wrong type inference when applying the above rule):

  let $a := &lt;a&gt;&lt;b/&gt;&lt;b/&gt;&lt;b/&gt;&lt;b/&gt;&lt;/a&gt; return
    $a/b[fn:subsequence( (1,2), last() )]

In this query, $a/b evaluates to 4 nodes.  last() will thus return
4, which is greater than the length of the sequence (1,2).  So the
result of fn:subsequence( (1,2), last() ) will be the empty
sequence, while we get `xs:integer&apos; as the static return type for
it.

If we replace the sequence (1,2) in the above example by (1,2,3,4,5),
fn:subsequence() will return a list of length 2, though the static
type is (still) `xs:integer&apos;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5692</commentid>
    <comment_count>1</comment_count>
    <who name="Jens Teubner">jens.teubner</who>
    <bug_when>2005-09-03 13:32:17 +0000</bug_when>
    <thetext>(In reply to comment #0)

&gt; If we replace the sequence (1,2) in the above example by (1,2,3,4,5),
&gt; fn:subsequence() will return a list of length 2, though the static
&gt; type is (still) `xs:integer&apos;.

Sorry, I just realized that the rule given in the specs actually
includes the length argument of fn:subsequence().  So my last
statement does not actually hold.  The problem stated before,
however, remains.  Sorry for the confusion.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5724</commentid>
    <comment_count>2</comment_count>
    <who name="Jerome Simeon">simeon</who>
    <bug_when>2005-09-06 15:49:22 +0000</bug_when>
    <thetext>Yes, this is correct. The rule you mention is wrong, that was picked up
already following the treatment of a previous bug report (#1728).

The WGs have already decided to remove that rule.

Thanks for your feedback,
- Jerome Simeon

*** This bug has been marked as a duplicate of 1728 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>