<?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>9258</bug_id>
          
          <creation_ts>2010-03-17 00:00:42 +0000</creation_ts>
          <short_desc>Static typing tests do not account for earlier static error</short_desc>
          <delta_ts>2010-06-08 21:56:35 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XQuery Update Facility Test Suite</product>
          <component>XQuery Update Facility Test Suite</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</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="Josh Spiegel">josh.spiegel</reporter>
          <assigned_to name="Michael Dyck">jmdyck</assigned_to>
          <cc>jmdyck</cc>
    
    <cc>josh.spiegel</cc>
    
    <cc>liam</cc>
    
    <cc>zhen.liu</cc>
          
          <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>33639</commentid>
    <comment_count>0</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2010-03-17 00:00:42 +0000</bug_when>
    <thetext>The following tests:

stf-insert-into-01
stf-insert-after-01 
stf-replace-node-01
stf-replace-value-of-node-01 
stf-rename-01
stf-transform-01

Can throw XPTY0004 before the error the test expects occurs.  The reason is that they contain path expressions like:

$input-context/works/employee[@name=&apos;Jane Doe 1&apos;]

$input-context has the static type document-node() or item()* depending on if a &quot;as document-node()&quot; rewrite described in the XQUTS guidelines is used or not.  Either way, the derived content type of @name will be anyAtomicType.  Consequently, the the static type check on the comparison between anyAtomicType and string will fail with XPTY0004.

These tests should be modified so that XPTY0004 can not occur and the intended error condition is always tested.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33723</commentid>
    <comment_count>1</comment_count>
    <who name="zhen hua liu">zhen.liu</who>
    <bug_when>2010-03-19 21:32:05 +0000</bug_when>
    <thetext>in http://dev.w3.org/2007/xquery-update-10-test-suite/TestSuiteDocumentation/Guidelines%20for%20Running%20the%20XML%20Query%20Update%20Test%20Suite.html,
we shall add (xs:untyped) in document-node() definition
Users of static typing may choose to transform the variable declarations between insert-start and insert-end comments by adding an &quot;as document-node(xs:untyped)&quot; clause as illustrated below:

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33724</commentid>
    <comment_count>2</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2010-03-19 22:08:59 +0000</bug_when>
    <thetext>Sounds good.  I verified that modifying our test framework to rewrite the variable declaration using &quot;as document-node(element(*, xs:untyped))&quot; fixes the problem.  Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33811</commentid>
    <comment_count>3</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2010-03-23 16:50:11 +0000</bug_when>
    <thetext>Why was this closed?  It does not appear that the guidelines have been changed yet.  Why is this bug &quot;invalid&quot;?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33814</commentid>
    <comment_count>4</comment_count>
    <who name="Andrew Eisenberg">andrew.eisenberg</who>
    <bug_when>2010-03-23 19:21:46 +0000</bug_when>
    <thetext>Apologies. I read your issue and Zhen&apos;s response too quickly and thought that you were satisfied with our current guidelines.

I believe that you are asking us to extend the guidelines, allowing the adding of both &quot;as document-node()&quot; and &quot;as document-node(element(*, xs:untyped))&quot;.

I&apos;m not strong in our static typing, so I&apos;ll have to ask some of our other members to comment on this. I note that we&apos;ve had similar requests in the past in Bug #3012, Bug #3972, Bug #4046, and Bug #7216.

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33817</commentid>
    <comment_count>5</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2010-03-23 19:31:26 +0000</bug_when>
    <thetext>No problem.  Yes, your understanding is correct.  Another option is to modify the 6 tests.  Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33821</commentid>
    <comment_count>6</comment_count>
    <who name="zhen hua liu">zhen.liu</who>
    <bug_when>2010-03-23 21:38:30 +0000</bug_when>
    <thetext>Allowing users to set
document-node(element(*), xs:untyped)

shall solve the problem without modifying the tests.
However,
We need to state so in
http://dev.w3.org/2007/xquery-update-10-test-suite/TestSuiteDocumentation/Guidelines%20for%20Running%20the%20XML%20Query%20Update%20Test%20Suite.html
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33824</commentid>
    <comment_count>7</comment_count>
    <who name="Andrew Eisenberg">andrew.eisenberg</who>
    <bug_when>2010-03-23 22:47:43 +0000</bug_when>
    <thetext>(In reply to comment #6)
&gt; Allowing users to set
&gt; document-node(element(*), xs:untyped)
&gt; shall solve the problem without modifying the tests.

Zhen, is this a necessary change? Is there a problem with these test cases if only &quot;as document-node()&quot; is added?

 </thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33826</commentid>
    <comment_count>8</comment_count>
    <who name="zhen hua liu">zhen.liu</who>
    <bug_when>2010-03-23 22:58:11 +0000</bug_when>
    <thetext>If only static type of &apos;docuement-node()&apos; is used, then it means the input document could be either untyped or typed, so this means the conservative static
typing has to raise static type errors for comparison in the predicate
employee[@name=&apos;Jane Doe 1&apos;]
since @name might be xs:integer, so it is an error to compare with xs:string.
This is what Josh explained in the original bug comment.
However, if we set the static type to &apos;document-node(element(*, xs:untyped)), then
no static type error is raised for handling the predicate comparison. So  the real intention of the test to test static typing for updating expression is
realized.


</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33982</commentid>
    <comment_count>9</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2010-03-28 06:04:18 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; Another option is to modify the 6 tests.

E.g., by changing &quot;@name&quot; to &quot;(@name treat as xs:string)&quot; ?

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33983</commentid>
    <comment_count>10</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2010-03-28 17:15:06 +0000</bug_when>
    <thetext>I would rewrite them as follows:

$input-context/works/employee[@name=&apos;Jane Doe 1&apos;]

becomes

$input-context/works/employee[1]
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33988</commentid>
    <comment_count>11</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2010-03-28 18:55:00 +0000</bug_when>
    <thetext>I don&apos;t think that would entirely work. The point of an expression like
    $input-context/works/employee[@name=&apos;Jane Doe 1&apos;]
is that its static type has cardinality greater than one, but its value has cardinality one. (So an implementation that supports the Static Typing Feature will raise a type error during static analysis, but an implementation that doesn&apos;t support the STF won&apos;t raise a type error at all.)

With an expression like
    $input-context/works/employee[1]
then, yes, when $input-context has the default static type item()*, the expression will still have the properties given above. But if an implementation chooses to replace the default declaration with:
    declare variable $input-context as document-node() external;
then I believe the Formal Semantics rules would cause it to infer a static type of cardinality zero-or-one for the expression, and therefore not raise a type error.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33990</commentid>
    <comment_count>12</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2010-03-28 19:12:21 +0000</bug_when>
    <thetext>You are right, I forgot you need the *.  Would $input-context/works/employee work?


</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33999</commentid>
    <comment_count>13</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2010-03-28 20:44:52 +0000</bug_when>
    <thetext>No, because then both the STF and non-STF implementations would raise a type error.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>34093</commentid>
    <comment_count>14</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2010-03-29 18:56:00 +0000</bug_when>
    <thetext>OK, then could we do a slight variation on your original suggestion?
&quot;@name&quot; to &quot;@name treat as attribute(name, xs:string)&quot;

or even 
&quot;@name&quot; to &quot;data(@name) treat as xs:string&quot;

Sorry, I am not trying to be difficult :)   

With your original suggestion, our implementation detects that even with the
treat expression, it is impossible for &quot;attribute (name, anyAtomicType)&quot; to
become &quot;xs:string&quot; at runtime so it still fails statically.  Note, the input to
the treat expression is not atomized. 
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>34637</commentid>
    <comment_count>15</comment_count>
    <who name="zhen hua liu">zhen.liu</who>
    <bug_when>2010-04-07 22:08:23 +0000</bug_when>
    <thetext>(: Name: stf-insert-into-01 :)
(: Description: insert-into: ST of TargetExpr has cardinality greater than one. :)
The purpose of this test is to show ST raises static type error by infering
the $target has static type with occurance of either &apos;zero or one&apos;, or &apos;zero or
more&apos;.
So
$input-context/works/employee[1] shall raise static type 
error as the ST is zero or one of element(employee)
and
$input-context/works/employee[@name=&apos;Jane Doe 1&apos;] shall raise static type
error as the ST is zero or more element(employee)

$input-context/works/employee[@name=&apos;Jane Doe 1&apos;] shall raise static type
error as the ST is zero or more element(employee)


So as long as we set the static type
for $input-context to &apos;document-node(element(*, xs:untyped)), the expected
static type would be raised without the need of changing the tests.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>34638</commentid>
    <comment_count>16</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2010-04-07 22:13:58 +0000</bug_when>
    <thetext>Zhen - I agree that changing the guidelines or changing the tests will fix the problem.  Why do you think changing the guidelines is better?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>34639</commentid>
    <comment_count>17</comment_count>
    <who name="zhen hua liu">zhen.liu</who>
    <bug_when>2010-04-07 22:25:39 +0000</bug_when>
    <thetext>No difference between changing the tests or the guideline of 
setting $input-context to &apos;document-node(element(*, xs:untyped)).

However, in general to really test
more on static typing (pessimistic based), it helps more to set
$input-context to &apos;document-node(element(*, xs:untyped))
instead of
setting $input-context to &apos;document-node(element(*)).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>34640</commentid>
    <comment_count>18</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2010-04-08 00:31:21 +0000</bug_when>
    <thetext>Currently, the XQUTS guidelines *allow* the test harness to add
    as document-node()
to the decl for $input-context. In order for the six tests in question to work unchanged, we&apos;d have to *require* the test harness to add
    as document-node(element(*, xs:untyped))
So that&apos;s two changes.

Moreover, I believe there are test-cases in XQUTS for which requiring that addition could cause problems. E.g., for a query involving books.xml, if an implementation constructs a typed XDM instance for the document, then it can&apos;t bind that value to a variable that has been declared as document-node(element(*, xs:untyped)). So the guidelines would have to address that somehow.

If instead we change the six queries, then the guidelines (and thus test harnesses) don&apos;t need to change. (My guess is that it&apos;s easier for implementors to rerun the suite with changed queries than it is for them to change their test harnesses.)

A third approach would be to change the six queries, but rather than tweaking the @name in the query body, explicitly add &quot;as document-node(element(*, xs:untyped))&quot; to the declaration of $input-context.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>35268</commentid>
    <comment_count>19</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2010-04-27 17:13:01 +0000</bug_when>
    <thetext>Josh, how do you feel about my &quot;third approach&quot;? (Explicitly change the declared type of $input-context in those six queries, and leave the query bodies as is.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>35269</commentid>
    <comment_count>20</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2010-04-27 17:29:24 +0000</bug_when>
    <thetext>So to recap, I think we have three viable options suggested:

(a) Modify the queries with something like &quot;@name treat as attribute(name, xs:string)&quot;

(b) Modify the test guidelines to require a rewrite of the variable declaration as &quot;document-node(element(*, xs:untyped))&quot;

(c) Modify the queries to rewrite the variable declaration as &quot;document-node(element(*, xs:untyped))&quot;

Based on what Michael points out in Comment #18, I would vote against (b).  I would be happy with (a) or (c).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>36056</commentid>
    <comment_count>21</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2010-06-08 21:55:54 +0000</bug_when>
    <thetext>At its meeting on 2010-05-18, the XQuery WG decided to adopt the solution given as option (c) in comment 20. I have made the necessary changes (in both XQuery and XQueryX versions of the queries) in XQUTS. Therefore, I am marking this bug resolved-FIXED.

Since you said you would be happy with this option (c), I am also taking the liberty of marking this bug CLOSED.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>