This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 1968 - typing for fn:subsequence() too strict
Summary: typing for fn:subsequence() too strict
Status: CLOSED DUPLICATE of bug 1728
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Formal Semantics 1.0 (show other bugs)
Version: Last Call drafts
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Jerome Simeon
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-03 12:17 UTC by Jens Teubner
Modified: 2005-09-08 16:46 UTC (History)
0 users

See Also:


Attachments

Description Jens Teubner 2005-09-03 12:17:31 UTC
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 := <a><b/><b/><b/><b/></a> 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' 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'.
Comment 1 Jens Teubner 2005-09-03 13:32:17 UTC
(In reply to comment #0)

> 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'.

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.
Comment 2 Jerome Simeon 2005-09-06 15:49:22 UTC
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 ***