Skip to content

Commit

Permalink
When coercing to a union type, atomize first before considering alter…
Browse files Browse the repository at this point in the history
…natives.
  • Loading branch information
michaelhkay committed May 4, 2024
1 parent c5de297 commit 397d810
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions specifications/xquery-40/src/expressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7024,7 +7024,29 @@ name.</p>
sequence, given a required <termref def="dt-item-type"/> <var>R</var>.</p>

<olist>
<item><p>If <var>R</var> is a <termref def="dt-choice-item-type"/> or
<item><p>If <var>R</var> is a <termref def="dt-generalized-atomic-type"/>
(for example, if it is an <termref def="dt-atomic-type"/>,
a <termref def="dt-pure-union-type"/>, or
an <termref def="dt-enumeration-type"/>), and <var>J</var>
is not an atomic value, then:
<olist>
<item><p><var>J</var> is atomized to produce a sequence of atomic values
<var>JJ</var>.</p></item>
<item><p>Each atomic value in <var>JJ</var> is coerced to the required
type <var>R</var> by recursive application of the item coercion rules (the
rules in this section) to produce a value <var>V</var>.</p></item>
<item><p>The result is the sequence-concatenation of the <var>V</var> values.</p></item>
</olist>
</p>
<note><p>For example, if <code>J</code> is an element with type annotation
<code>xs:integer</code>, and <code>R</code> is the union type <code>xs:numeric</code>,
then the effect is to atomize the element to an <code>xs:integer</code>, and then
to coerce the resulting <code>xs:integer</code> to <code>xs:numeric</code>
(which leaves the integer unchanged). This is not the same as attempting to
coerce the element to each of the alternatives of the union type in turn, which
would deliver an instance of <code>xs:double</code>.</p></note>
</item>
<item><p>Otherwise, if <var>R</var> is a <termref def="dt-choice-item-type"/> or
a <termref def="dt-pure-union-type"/> (which includes the case where
it is an <termref def="dt-enumeration-type"/>), then:</p>

Expand Down Expand Up @@ -7086,7 +7108,7 @@ name.</p>
<termref def="dt-choice-item-type">choice item types.</termref></p></note>
</item>

<item>
<!--<item>
<p>If <var>R</var> is an <termref def="dt-atomic-type"/>
and <var>J</var> is not an atomic value,
then <var>J</var> is <termref def="dt-atomization">atomized</termref>.
Expand All @@ -7096,7 +7118,7 @@ name.</p>
these atomic values in turn, with the same item type <var>R</var>
as the required type, and the results are concatenated
in order to form the result sequence.</p>
</item>
</item>-->

<item>
<p>If <var>R</var> is an <termref def="dt-atomic-type"/>
Expand Down

0 comments on commit 397d810

Please sign in to comment.