[feature] XQuery 4.0 type coercion rules - #6260
Conversation
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>
|
@reinhapa any new thoughts? |
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>
Convert version if-else chain in XQueryTree.g to switch-as-expression. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Simplify DynamicTypeCheck.isXQ4ImplicitCast to a single boolean return, dropping the xs:double/xs:float to xs:decimal cases already subsumed by the any-numeric to any-numeric rule; collapse the boolean return in isXQ4Relabeling; and extract the XQuery 4.0 coercion disjunct in Function.checkArgumentType into an isXQ4CoercionAllowed helper so it no longer inflates that method's condition. No behavior change; the full XQuery3Tests suite (including the XQ4 type-promotion tests) still passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
826ef2d to
43f21ab
Compare
|
[This response was prompted by Joe, drafted by Claude Code, and reviewed by Joe.] Picked this one back up. Two updates, and a scope question for you all. Rebased and green. The branch was ~930 commits behind, and the earlier Windows CI failure turned out to be purely the 45-minute integration-test timeout (no test failures) — which is long gone on current develop (that job now finishes in ~24 min). Rebased onto develop (clean, no conflicts), the full suite passes, and CI is green. A scope finding worth your input. I ran the actual QT4
The four failures aren't in the argument coercion this PR implements — The question: how would you like to handle the comparison-coercion gap?
We'd lean toward (1) — it keeps a reviewable, spec-correct increment moving and separates a genuinely different mechanism — but this is squarely your call, especially given XQ4 is parked behind 7.0 for now. Happy to open a tracking issue for the comparison-coercion follow-up if that's useful. |
|
I agree with (1) "as is" |
|
same here 3.1 as is |
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