Skip to content

Commit

Permalink
Merge pull request qt4cg#1501 from ChristianGruen/1318
Browse files Browse the repository at this point in the history
1318 Function Coercion: Records, Maps, Arrays
  • Loading branch information
ndw authored Oct 29, 2024
2 parents a8d96d7 + 8590cf1 commit d9befb9
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions specifications/xquery-40/src/expressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7267,12 +7267,41 @@ declare record Particle (

</item>


<item diff="add" at="A">
<p>If <var>R</var> is an <nt def="ArrayType"
>ArrayType</nt> other than <code>array(*)</code> and <var>J</var>
is an array, then <var>J</var> is converted to a new array by converting
each member to the required member type by applying the coercion rules
recursively.</p>
<note><p>For example, if the required type is
<code>array(xs:double)</code> and the supplied value is
<code>[ 1, 2 ]</code>, the array is converted to
<code>[ 1e0, 2e0 ]</code>.</p></note>
</item>

<item diff="add" at="A">
<p>If <var>R</var> is a <nt def="MapType"
>MapType</nt> other than <code>map(*)</code> and <var>J</var>
is a map, then <var>J</var> is converted to a new map as follows:</p>
<olist>
<item><p>Each key in the supplied map is converted to the required
map key type by applying the coercion rules. If the resulting map would
contain duplicate keys, a type error is raised
<errorref class="TY" code="0004"/>.</p></item>
<item><p>The corresponding value is converted to the required
map value type by applying the coercion rules recursively.</p></item>
</olist>





<note><p>For example, if the required type is
<code>map(xs:string, xs:double)</code> and the supplied value is
<code>{ "x": 1, "y": 2 }</code>, the map is converted to
<code>{ "x": 1e0, "y": 2e0 }</code>.</p></note>
<note><p>Duplicate keys can occur if the value space of the target type
is more restrictive than the original type. For example, an error is raised
if the map <code>{ 1.2: 0, 1.2000001: 0 }</code>, which contains two keys
of type <code>xs:decimal</code>, is coerced to the type
<code>map(xs:float, xs:integer)</code>.</p></note>
</item>

<item diff="add" at="A">
<p>If <var>R</var> is a <nt def="RecordType"
Expand Down Expand Up @@ -7310,8 +7339,7 @@ declare record Particle (
the expected item type <var>R</var> according to the rules for <termref
def="dt-sequencetype-matching"
>SequenceType
Matching</termref>, a <termref def="dt-type-error"
>type error</termref> is
Matching</termref>, a type error is
raised <errorref class="TY" code="0004"
/>.</p>
<note diff="add" at="Issue602">
Expand Down

0 comments on commit d9befb9

Please sign in to comment.