Project

Profile

Help

Something wrong with last() in Saxon 11.1

Added by Vladimir Nesterovsky about 2 years ago

Though it's not a complete reproduction, I want to give you heads up on a problem, which might be related to https://saxonica.plan.io/issues/5281.

I have a code that reads like this:

<xsl:if test="$columns">
  <xsl:variable name="last-offsets" as="xs:decimal+" select="
    t:get-offsets($columns[last()], $last-bounds, $header-bounds)"/>

Processor reports runtime error:

An empty sequence is not allowed as the first argument of t:get-offsets()

I see no way how this message can be true, unless it reports completely wrong line numbers. Besides, the same code works in Saxon 10.

When I add <xsl:message select="$columns"/> as a first instruction inside <xsl:if> it prints non empty sequence of elements, yet error is still there.

When I change code to:

  <xsl:variable name="last-offsets" as="xs:decimal+" select="
    t:get-offsets($columns[last()]=>trace('last'), $last-bounds, $header-bounds)"/>

then before crash I see: last: empty sequence

I don't even know what part of code to isolate to create a small reproducible sample. I shall probably skip this version and try the next one. If problem will still be there then I'll try to create a repro.


Replies (4)

Please register to reply

RE: Something wrong with last() in Saxon 11.1 - Added by Vladimir Nesterovsky about 2 years ago

One more attempt.

Following:

<xsl:variable name="last-offsets" as="xs:decimal+" select="
  t:get-offsets($columns[last()]=>trace('last, ' || count($columns)), $last-bounds, $header-bounds)"/>

prints: last, 25: empty sequence

RE: Something wrong with last() in Saxon 11.1 - Added by Michael Kay about 2 years ago

Yes, this looks like exactly the same problem as #5281.

Remarkable that two users should hit it so quickly and that none of our tens of thousands of tests should do so.

I think the precise conditions are

(a) the variable is being lazily-evaluated (which is pretty much the default)

(b) it has been fully evaluated already, which means you've done something that required access to the last item in the sequence.

(c) you then do something that tries to get a reverse-order iterator over the value, of which the most common case is an expression like $var[last()].

RE: Something wrong with last() in Saxon 11.1 - Added by Vladimir Nesterovsky about 2 years ago

I have:

<xsl:for-each select="$columns">
  do something
</xsl:for-each>
          
<xsl:if test="$columns">
  do something more about last column
</xsl:if>

RE: Something wrong with last() in Saxon 11.1 - Added by Michael Kay about 2 years ago

Yes, that matches the scenario pretty much exactly.

    (1-4/4)

    Please register to reply