Thanks for reporting it! Very curious.
I added to line 3 so it reads
if (empty(trace($todo, '$todo'))) then
and the trace is the same for 10.x and 11.1 until we get to:
10.x:
$todo [1]: text(): root/text()[36]
$todo [1]: element(fragment, xs:untyped): root/fragment[23]
$todo [1]: element(fragment, xs:untyped): root/fragment[24]
$todo [1]: element(fragment, xs:untyped): root/fragment[25]
$todo [1]: element(tab, xs:untyped): root/tab[39]
$todo [1]: element(fragment, xs:untyped): root/fragment[26]
$todo [1]: element(tab, xs:untyped): root/tab[40]
$todo [1]: text(): root/text()[37]
at which point 11.1 does:
$todo [1]: text(): root/text()[36]
$todo [1]: element(fragment, xs:untyped): root/fragment[23]
$todo [1]: element(fragment, xs:untyped): root/fragment[24]
$todo [1]: element(fragment, xs:untyped): root/fragment[25]
$todo [1]: element(tab, xs:untyped): root/tab[39]
$todo [1]: element(fragment, xs:untyped): root/fragment[26]
$todo [1]: element(tab, xs:untyped): root/tab[40]
$todo: empty sequence
(note that empty()
only reads, and therefore only traces, the first item in the sequence)
The failure occurs with or without bytecode generation.
Now I've added tracing on the value of count($todo)
, and in 10.x it drops incrementally down to zero, whereas in 11.1 it drops incrementally down to 12, and then ends with
$todo [1]: element(tab, xs:untyped): root/tab[40]
$count [1]: xs:integer: 12
$todo: empty sequence
I'm now breakpointing at the point where the trace(count) returns "12".
The next $item is <tab col="9"/>
.
I see here that the value of the parameter $todo was a ZenoChain with segment lengths 1 and 12, and the result of evaluating tail()
on this (written as $todo[position()>1]
) is a ZenoChain with segment lengths 0 and 12. This is incorrect: the first segment should have been removed, rather than being reduced to zero length, and this is almost certainly why the test on empty() has gone wrong.
The ZenoChain structure is new in 11.x - it's an immutable list structure optimised for recursive addition or removal of items at the start or end of a sequence, designed to reduce the amount of copying that occurs when sequences are built incrementally.
Or to be a little more precise, ZenoSequence
is an immutable list structure built on top of ZenoChain
which is itself mutable. Both of them could do with better JavaDoc.