Hi Nico,
Thanks for the observation. A new stable snapshot with the bug fix is online [1,2]. BaseX 12.3 is scheduled for February or March.
Cheers,
Christian
Von: Nico Kutscherauer via BaseX-Talk
Gesendet: Mittwoch, 11. Februar 2026 14:08
Bis: basex-talk@mailman.uni-konstanz.de
Betreff: [basex-talk] Bug where sorting arrays causes a type error?
Hi BaseX team,
I have the following simple query:
let $strings := ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j')
let $arrays as array(*)* := (array{1 to 2}, array{3 to 6}, array{7 to 9})
let $arrays := sort($arrays, (), fn($seq){array:size($seq) * -1})
let $largest := $arrays => head()
return
for $idx in $largest?* return $strings[$idx]
When I execute it with BaseX 12.2 I get the following suprising error:
[XPTY0004] One item expected, 4 found: (3 to 6).
Much more suprising is that if I wrap the $arrays?* into a trace call it works:
let $strings := ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j')
let $arrays as array(*)* := (array{1 to 2}, array{3 to 6}, array{7 to 9})
let $arrays := sort($arrays, (), fn($seq){array:size($seq) * -1})
let $largest := $arrays => head()
return
for $idx in trace($largest?*) return $strings[$idx]
Result:
c
d
e
f
The root cause seems to be the sort function. Because if I remove that line it works without the trace.
Best Regards,
Nico
--
Nico Kutscherauer
XML Developer
data2type GmbH
Im Breitspiel 6A
69126 Heidelberg
Tel.: +49-(0)6221-73 912 60
www.data2type.de
Workingdays: Tue/Wed/Thu/Fri(HO)
Workinghours: 10-18.30
Company’s head office: Heidelberg
Commercial Register court: AG Mannheim HRB 715195
CEO: Manuel Montero Pineda