<?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>6625</bug_id>
          
          <creation_ts>2009-02-25 16:57:22 +0000</creation_ts>
          <short_desc>[FS] Type unsoundness of axis expressions involving nillable elements substitutable for non-nillable elements</short_desc>
          <delta_ts>2009-02-25 16:57:22 +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>Formal Semantics 1.0</component>
          <version>Candidate 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="Oliver Hallam">oliver</reporter>
          <assigned_to name="Michael Dyck">jmdyck</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>23934</commentid>
    <comment_count>0</comment_count>
    <who name="Oliver Hallam">oliver</who>
    <bug_when>2009-02-25 16:57:22 +0000</bug_when>
    <thetext>Start with the following schema:

&lt;schema targetNamespace=&quot;http://www.xqsharp.com/test&quot;
        xmlns:t=&quot;http://www.xqsharp.com/test&quot;
	xmlns=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;

  &lt;element name=&quot;head&quot; type=&quot;string&quot; /&gt;
  
  &lt;element name=&quot;sub&quot; substitutionGroup=&quot;t:head&quot; nillable=&quot;true&quot; /&gt;
  
  &lt;element name=&quot;root&quot;&gt;
    &lt;complexType&gt;
      &lt;sequence&gt;
        &lt;element ref=&quot;t:head&quot; /&gt;
      &lt;/sequence&gt;
    &lt;/complexType&gt;
  &lt;/element&gt;

&lt;/schema&gt;


which looks something like this when translated to the XQuery type system:

define element head of type xs:string;
define element sub substitutes head nillable of type xs:string;
define type fs:anon1 { element head }
define element root of type fs:anon1


now consider the following query:

import schema namespace t=&quot;http://www.xqsharp.com/test&quot;;

let $root as schema-element(t:root) := (validate{ . })/t:root
return $root/node()


Let us compute the static type of this query.

$root has static type element t:root


According to the revised judgements given in bug 4189, comment 4:

Definition = define type fs:anon1 { element head }
inheritance due to  is empty
element head opt-mixes to element head
type definitions derived from fs:anon1 are empty
------------------------------------------------
union interpretation of define type fs:anon1 { element head } is element head


and again, from bug 4189, comment 4:

fs:anon1 of elem/type expands to fs:anon1
statEnv.typeDefn(fs:anon1) = define type fs:anon1 { element head }
union interpretation of define type fs:anon1 { element head } is element head
element head adjusts to (BuiltInAttributes, element head) &amp; processing-instruction* &amp; comment*
------------------------------------------------
element head of elem/type expands to (BuiltInAttributes, element head) &amp; processing-instruction* &amp; comment*

(where I have not bothered to expand out the built in attributes)


thus (from the first rule in FS 8.2.2.1.3):
element root type lookup fs:anon1
fs:anon1 expands to (BuiltInAttributes, element head) &amp; processing-instruction* &amp; comment*
element head has node content (element head &amp; processing-instruction* &amp; comment*)
-------------------------------------------
axis child:: of element root : element head &amp; processing-instruction* &amp; comment*


and finally (FS 8.2.3.1.2):

test node() with PrincipalNodeKind of element head : element head


Skipping the rest of the expansion/judgements we end up with

$root/node() : element head


Now take take the following context document:
&lt;root xmlns=&quot;http://www.xqsharp.com/test&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
  &lt;sub xsi:nil=&quot;true&quot; /&gt;
&lt;/root&gt;

The result of the query is the nilled sub element, but this does not match the static type, since element head is not nillable.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>