Skip to content

Commit 154ce4d

Browse files
joewizclaude
andcommitted
[bugfix] SequenceType: restrict function-arity check to function() typed tests
Commit 0d96ad8 added function-arity + return-type checking in SequenceType.checkType under Type.subTypeOf(primaryType, Type.FUNCTION). Because MAP_ITEM and ARRAY_ITEM are declared subtypes of FUNCTION, the arity check also applied to typed map(K,V) and array(T) tests -- but the underlying map accessor signature carries one argument (the key), while map(K,V) carries two type parameters in the test syntax. The arity comparison therefore always returned false, so any "$x instance of map(xs:string, item()?)" check failed and the value flowed down the else branch unchanged. Concretely this caused the xquery3 recursion-function-calls-002 test to fail with FOTY0013 ("A function item other than an array cannot be atomized") when the recursive local:join was bypassed and a raw map landed inside string-join. Narrow the function-type check to primaryType == Type.FUNCTION so the plain function() typed-test still gets validated (including on map and array values that satisfy it via FUNCTION subtyping), while map(K,V) and array(T) tests revert to their pre-0d96ad8a19 behaviour pending proper typed-test support. Also: update the id.xqm securitymanager fixture's stored module from 'xquery version "3.0"' to "3.1" so that the stricter loaded-module version check added in 7966280 no longer rejects it. Addresses Juri's second review comment on PR eXist-db#6344 (recursion-function- calls-002 failure). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 327393c commit 154ce4d

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

exist-core/src/main/java/org/exist/xquery/value/SequenceType.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,14 @@ public boolean checkType(final Item item) {
177177
return false;
178178
}
179179

180-
// For function types, check parameter and return type compatibility
181-
if (Type.subTypeOf(primaryType, Type.FUNCTION) && item instanceof FunctionReference
180+
// For typed function() tests, check parameter and return type compatibility.
181+
// MAP_ITEM and ARRAY_ITEM are subtypes of FUNCTION but use distinct typed-test
182+
// syntax (map(K,V), array(T)) whose parameter counts do not match the
183+
// underlying function signature's argument count (a map's accessor signature
184+
// takes 1 arg, the key; map(K,V) carries 2 type parameters). Restrict the
185+
// function-arity/return check to plain function() tests so map and array
186+
// values continue to satisfy their typed tests.
187+
if (primaryType == Type.FUNCTION && item instanceof FunctionReference
182188
&& !checkFunctionType((FunctionReference) item)) {
183189
return false;
184190
}

exist-core/src/test/xquery/securitymanager/id.xqm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ declare
3535
%test:setUp
3636
function id:setup() {
3737
xmldb:create-collection("/db", $id:TEST_COLLECTION_NAME),
38-
xmldb:store($id:TEST_COLLECTION_PATH, $id:TEST_MODULE_NAME, 'xquery version "3.0";
38+
xmldb:store($id:TEST_COLLECTION_PATH, $id:TEST_MODULE_NAME, 'xquery version "3.1";
3939
4040
module namespace mod1 = "http://module1";
4141

0 commit comments

Comments
 (0)