Skip to content

Commit

Permalink
Fix ForClause PositionalVar empty sequence handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin6939 committed Dec 25, 2024
1 parent fc7c447 commit bca2b7a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion exist-core/src/main/java/org/exist/xquery/ForExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ private void processItem(LocalVariable var, Item contextItem, Sequence in, Seque
context.proceed(this);
context.setContextSequencePosition(p, in);
if (positionalVariable != null) {
at.setValue(new IntegerValue(this, p + 1));
if(contextItem.getType() == Type.ANY_ATOMIC_TYPE)
at.setValue(new IntegerValue(this, 0));
else
at.setValue(new IntegerValue(this, p + 1));
}
final Sequence contextSequence = contextItem.toSequence();
// set variable value to current item
Expand Down
14 changes: 14 additions & 0 deletions exist-core/src/test/xquery/xquery3/flwor.xql
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,17 @@ function flwor:allowing-empty($n as xs:integer) {
return concat("[", $x, "]")
};

declare
%test:args(4)
%test:assertEquals(":0")
%test:args(2)
%test:assertEquals("b:1")
%test:args(1)
%test:assertEquals("a:1")
%test:args(5)
%test:assertEquals(":0")
function flwor:allowing-empty-fix($n as xs:integer) {
let $sequence := ("a", "b", "c")[$n]
for $x allowing empty at $y in $sequence
return $x || ":" || $y
};

0 comments on commit bca2b7a

Please sign in to comment.