<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>30317</bug_id>
          
          <creation_ts>2018-11-08 20:52:59 +0000</creation_ts>
          <short_desc>[XP31] Subtype rules for maps tested against functions conflict, because of zero-or-one cardinality in rule 35</short_desc>
          <delta_ts>2018-11-08 20:52:59 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XPath 3.1</component>
          <version>Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Abel Braaksma">abel.online</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>129383</commentid>
    <comment_count>0</comment_count>
    <who name="Abel Braaksma">abel.online</who>
    <bug_when>2018-11-08 20:52:59 +0000</bug_when>
    <thetext>A map item can have a value of type item()*. The rules for the subtype relationship (2.5.6.2 The judgement subtype-itemtype(Ai, Bi)) for maps state:

35. Ai is map(K, V), and Bi is function(xs:anyAtomicType) as V?. 

I see two issues with this statement:

1) Bi can be any subtype of function(xs:anyAtomicType) as V?. It doesn&apos;t have to be exactly that type.

2) It should be V*, not V?

Example: map{&apos;a&apos;: (1, 2)} instance of function(xs:int) as item()?

a) Current rules

The map type of map(K, V) is: map(xs:string, xs:integer*)

The corresponding function then becomes: function(xs:anyAtomicType) as xs:integer?

Result of the type test would then be true, but that is clearly wrong, considering the co-variance of the return type.

b) If we replace V? with V* 

Now the rewrite is instead: function(xs:anyAtomicType) as xs:integer*

Now the instance-of expressions would correctly return true.

Saxon gets it right with the (b) scenario, even though that is at odds with the spec. I think (b) is the correct approach.

The same error can be found in section 2.5.5.8 Map Test.

I propose the rule be rewritten in an erratum, something along these lines:

&lt;proposal&gt;
35. Ai is map(K, V), and Bi is function(xs:anyAtomicType) as V* or a subtype thereof. 
&lt;/proposal&gt;

This change would, however, lead to  map{&apos;a&apos;: 1} being no longer a subtype of function(xs:int) as item()?

To fix that, we could write it as follows:

&lt;proposal&gt;
35. Ai is map(K, VA), and Bi is function(KB) as VB, where subtype(VA, VB) and subtype-itemtype(KB, xs:anyAtomicType).
&lt;/proposal&gt;

This latter syntax would be more in line with rule 28, also on maps and emphasizes the co-variance/contra-variance rules that are in place here.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>