<?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>16089</bug_id>
          
          <creation_ts>2012-02-23 10:33:18 +0000</creation_ts>
          <short_desc>[FO30] cast vs. constructors (FunctionCall-015)</short_desc>
          <delta_ts>2012-05-08 20:03:07 +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.0</component>
          <version>Member-only Editors Drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>RESOLVED</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>
          <dependson>16149</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tim Mills">tim</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>jonathan.robie</cc>
    
    <cc>mike</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>64482</commentid>
    <comment_count>0</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2012-02-23 10:33:18 +0000</bug_when>
    <thetext>I&apos;m unable to spot the type check error in this test case.  From the comment, I suspect it relatese to 

xs:QName(&lt;f&gt;local:f&lt;/f&gt;)

Applying 3.1.5.2 Function Conversion Rules, 

1. Atomization is applied to the given value, resulting in a sequence of atomic values.  

   This gives xs:QName(xs:untypedAtomic(&quot;local:f&quot;)

2. Expected type of constructor function xs:QName in xs:anyAtomicType?.  This is not namespace-sensitive.  Therefore XPTY0117 is not raised.

3. Result is xs:QName(xs:untypedAtomic(&quot;local:f&quot;)) (not an error in XQ30).

Am I missing something?

BTW, I&apos;m not sure this test really depends on schema validation.

   &lt;test-case name=&quot;FunctionCall-015&quot;&gt;
      &lt;description&gt;Test that arguments are atomized - but not the argument of casting to QName&lt;/description&gt;
      &lt;created by=&quot;Michael Kay&quot; on=&quot;2011-10-31&quot;/&gt;
      &lt;dependency type=&quot;spec&quot; value=&quot;XQ30+&quot;/&gt;
      &lt;dependency type=&quot;feature&quot; value=&quot;schemaValidation&quot;/&gt;
      &lt;test&gt;&lt;![CDATA[
         declare function local:f($in as xs:integer) as xs:integer { $in + 1 };
         let $f := function-lookup(xs:QName(&lt;f&gt;local:f&lt;/f&gt;), 1)
         return $f(12)]]&gt;&lt;/test&gt;
      &lt;result&gt;
        &lt;error code=&quot;XPTY0004&quot;/&gt;
      &lt;/result&gt;
   &lt;/test-case&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64484</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2012-02-23 11:01:19 +0000</bug_when>
    <thetext>I think the reasoning is:

(a) the equivalent cast expression is an error under http://www.w3.org/TR/xpath-30/#id-cast rule 1

(b) Section 17.1 of F+O states &quot;The semantics of the constructor function &quot; xs:TYPE(arg) &quot; are identical to the semantics of &quot; arg cast as xs:TYPE? &quot;

But I agree, your argument seems reasonable, that the argument to the constructor function should be atomized in the same way as for any other function.

So I think we have a spec issue.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64485</commentid>
    <comment_count>2</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2012-02-23 11:13:13 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; I think the reasoning is:
&gt; 
&gt; (a) the equivalent cast expression is an error under
&gt; http://www.w3.org/TR/xpath-30/#id-cast rule 1
&gt; 
&gt; (b) Section 17.1 of F+O states &quot;The semantics of the constructor function &quot;
&gt; xs:TYPE(arg) &quot; are identical to the semantics of &quot; arg cast as xs:TYPE? &quot;
&gt; 
&gt; But I agree, your argument seems reasonable, that the argument to the
&gt; constructor function should be atomized in the same way as for any other
&gt; function.
&gt; 
&gt; So I think we have a spec issue.

I had suspected that, but checked 3.13.2 Cast.

1.  The input expression is evaluated.

2.  If the result contains a node, and the target type is namespace-sensitive, a type error [err:XPTY0117] is raised.

Since the target type (xs:anyAtomicType) is not namespace-sensitive, the semantics of the cast are equivalent to the constructor.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64486</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2012-02-23 11:24:15 +0000</bug_when>
    <thetext>But the equivalent cast expression is

&lt;f&gt;local:f&lt;/f&gt; cast as xs:QName

and the &quot;target type&quot; is therefore xs:QName.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64487</commentid>
    <comment_count>4</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2012-02-23 11:32:41 +0000</bug_when>
    <thetext>(In reply to comment #3)
&gt; But the equivalent cast expression is
&gt; 
&gt; &lt;f&gt;local:f&lt;/f&gt; cast as xs:QName
&gt; 
&gt; and the &quot;target type&quot; is therefore xs:QName.

Ooops - yes.  How unfortunate!

I&apos;ll mark this as a bug against the specification.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65812</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2012-03-20 11:03:24 +0000</bug_when>
    <thetext>I&apos;m inclined to think that the cleanest solution is to abandon the special rule (cast rule 1) that says atomization doesn&apos;t happen if the target type is namespace sensitive. It&apos;s a paternalistic rule that prevents people doing things whose effects might be surprising, but it causes orhogonality problems. The orthonogality problems are bearable for cast expressions, but are very disruptive if we try to carry the same rule through to constructor functions; and we really don&apos;t want to introduce a difference between casts and constructors.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65821</commentid>
    <comment_count>6</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2012-03-20 12:04:22 +0000</bug_when>
    <thetext>I agree with the solution proposed in Comment #5.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65846</commentid>
    <comment_count>7</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2012-03-20 15:55:03 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; I&apos;m inclined to think that the cleanest solution is to abandon the special rule
&gt; (cast rule 1) that says atomization doesn&apos;t happen if the target type is
&gt; namespace sensitive. It&apos;s a paternalistic rule that prevents people doing
&gt; things whose effects might be surprising, but it causes orhogonality problems.
&gt; The orthonogality problems are bearable for cast expressions, but are very
&gt; disruptive if we try to carry the same rule through to constructor functions;
&gt; and we really don&apos;t want to introduce a difference between casts and
&gt; constructors.

The Working Group has agreed to this change.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66612</commentid>
    <comment_count>8</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2012-04-11 09:06:06 +0000</bug_when>
    <thetext>I presume that this removes the raising of XPTY0117 in section 3.1.5.2 Function Conversion Rules.  Thus XPTY00117 is now redundant.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67496</commentid>
    <comment_count>9</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2012-05-08 20:03:07 +0000</bug_when>
    <thetext>(In reply to comment #8)
&gt; I presume that this removes the raising of XPTY0117 in section 3.1.5.2 Function
&gt; Conversion Rules.  Thus XPTY00117 is now redundant.

No, I don&apos;t think that was the intent.

There&apos;s a problem with the function conversion rules that doesn&apos;t apply to casts and constructors: there&apos;s no obvious choice of static context to get the namespaces from.

Using the static context of the function itself doesn&apos;t work for system functions and external functions (perhaps it doesn&apos;t even work for user-defined functions, as it&apos;s only expressions that have a static context).

Using the static context of the caller raises lots of problems with dynamic function invocation, function coercion, and the like. The rule would also need to cover cases where the (ill-named) function conversion rules are used for things other than converting function arguments, e.g. conversion of function results, or conversion of variable bindings in XSLT.

So I think the rule is still that conversion of untypedAtomic to QName does not happen in the function conversion rules.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>