[feature] XQuery 4.0 type coercion rules#6260
Open
joewiz wants to merge 2 commits into
Open
Conversation
Add version-gated XQ4 coercion rules that only apply when `xquery version "4.0"` is declared: - Implicit Casting (§3.4.1 item 4): xs:string → xs:anyURI, xs:hexBinary ↔ xs:base64Binary, bidirectional numeric coercion - Relabeling (§3.4.1 item 6): derived type acceptance when datum is within value space (e.g., xs:integer 3 → xs:positiveInteger) - Accept `xquery version "4.0"` in the parser Runtime coercion in DynamicTypeCheck, static check bypass in Function.java, version-gated integer→positiveInteger in UntypedValueCheck. No changes to the type hierarchy in Type.java. Includes 9 XQSuite tests covering all coercion rules plus a version-gating test confirming XQ 3.1 modules reject string→anyURI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
reinhapa
reviewed
Apr 25, 2026
Convert version if-else chain in XQueryTree.g to switch-as-expression. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
Author
joewiz
added a commit
to joewiz/exist
that referenced
this pull request
May 30, 2026
Per @duncdrum and @line-o on PR eXist-db#6344: both reviewers flagged the two xs:hexBinary ↔ xs:base64Binary code paths as XQ 4.0-specific (the comments literally say "(XQuery 4.0)") and noted they don't belong in this XQ 3.1 conformance subset. Removed: - DynamicTypeCheck.java: the xs:base64Binary ↔ xs:hexBinary type-promotion branch in the static-type-check ladder - GeneralComparison.java: case (d) of resolveNumericType — cast both operands of a general comparison to xs:base64Binary when both are binary types. Renumbered the now-final XPTY0004 case from (e) to (d). These will be reintroduced together with the rest of XQ 4.0 type coercion in v2/xq4-core-functions (PR eXist-db#6260). XQuery3Tests: 1030/1030 pass. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Merged
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
xquery version "4.0"xs:string → xs:anyURI,xs:hexBinary ↔ xs:base64Binary, bidirectional numericxs:integer3 accepted asxs:positiveInteger)xquery version "4.0"in the ANTLR tree walkerWhat Changed
XQueryTree.g— Acceptxquery version "4.0", setting context version to 40.DynamicTypeCheck.java— Newxq4ImplicitCast()method handles runtime coercion per spec §3.4.1:xs:string→xs:anyURI,xs:hexBinary↔xs:base64Binary, any numeric → any numericisXQ4ImplicitCast()andisXQ4Relabeling()arestaticfor reuse by the static checkFunction.java— Bypass static type check for XQ4 implicit casts and relabeling (line 305).UntypedValueCheck.java— Version-gate thexs:integer → xs:positiveIntegerrejection; allow in XQ4 per §3.4.1 item 6.xq4-type-promotion.xql— 8 XQSuite tests (XQ 4.0 module) covering all coercion rules.xq4-type-promotion-gating.xql— 1 version-gating test (XQ 3.1 module) confirmingxs:string→xs:anyURIis correctly rejected.Spec References
Design Decisions
Type.java— the type hierarchy is correct; coercion operates at the function argument level viaDynamicTypeCheck, exactly as the spec intendsxquery version "4.0"is declaredxs:time is not a sub-type of xs:dateTime) are NOT type promotion — they require function signature changes forfn:*-from-dateTime(QT4 PR1481), tracked separatelyTest Plan
function-call-promotion-*tests pass🤖 Generated with Claude Code