<?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>3686</bug_id>
          
          <creation_ts>2006-09-08 16:06:35 +0000</creation_ts>
          <short_desc>fn-matches2args-1 fails static typechecking.</short_desc>
          <delta_ts>2010-03-16 15:50:55 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XML Query Test Suite</product>
          <component>XML Query Test Suite</component>
          <version>1.0</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows XP</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>
          <dependson>3717</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tim Mills">tim</reporter>
          <assigned_to name="Carmelo Montanez">carmelo</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>11525</commentid>
    <comment_count>0</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2006-09-08 16:06:35 +0000</bug_when>
    <thetext>Queries such as:

fn:matches(xs:string(&quot;This is a characte&quot;),xs:string(&quot;This is a characte&quot;))

from:

fn-matches2args-1 

fail under static type checking, because

fn:matches($input as xs:string?, $pattern as xs:string) as xs:boolean
xs:string($arg as xs:anyAtomicType?) as xs:string?

i.e. the second argument is not guaranteed to return a string.  It may return an empty sequence.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11526</commentid>
    <comment_count>1</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2006-09-08 16:09:40 +0000</bug_when>
    <thetext>Other offending queries include:

fn-replace3args-1
fn-matches2args-1 to fn-matches2args-5
fn-replace3args-1 to fn-replace3args-7</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11528</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2006-09-08 16:24:31 +0000</bug_when>
    <thetext>&gt; fn:matches(xs:string(&quot;This is a characte&quot;),xs:string(&quot;This is a characte&quot;))

If this isn&apos;t a valid query then we&apos;ve clearly got something badly wrong, and it&apos;s not just the test case. 

Static Typing is identified in the CR as an &quot;at risk&quot; feature and this kind of report is leading me strongly to the view that we should pull it from the Rec and take more time to get it right.

IIRC, there was some pressure from Static Typing implementors to relax the signatures of some functions and operators (like matches) so that queries like the one above would work, and there was resistance from other implementors because it would reduce the ability for dynamic typing to detect errors. Perhaps we should think about allowing functions and operations to have a weaker type signature when static typing is in use. Or perhaps we need to make the type inference machinery more intelligent so that it (like any human being) can infer that the above example is actually type safe.

Michael Kay
(not speaking for the WG, of course)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11530</commentid>
    <comment_count>3</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2006-09-08 16:45:02 +0000</bug_when>
    <thetext>A simple fix might be to require that all constants are folded before static typing occurs?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11531</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2006-09-08 17:18:45 +0000</bug_when>
    <thetext>A formal definition of constant subexpressions might well be useful, but I don&apos;t think it would be simple.

Michael Kay</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11532</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Rys">mrys</who>
    <bug_when>2006-09-08 17:23:48 +0000</bug_when>
    <thetext>I was arguing in favor of relaxing the argument types to make them composable. But examples as the one given is of a lesser concern since xs:string(&quot;This is a characte&quot;) is bad coding style.

Our static typing implementation actually relaxes the argument types of these built-in functions to allow (). We should either do that change for at least static implementations - or if no consensus can be reached, we should allow static typing implementation to error on the test.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11552</commentid>
    <comment_count>6</comment_count>
    <who name="Frans Englich">frans.englich</who>
    <bug_when>2006-09-10 11:20:03 +0000</bug_when>
    <thetext>Many of these recent static typing reports are because of the &apos;cast as&apos;-inference isn&apos;t very clever(I think). It doesn&apos;t infer from its operand, but blindly goes on whether the &apos;?&apos; occurrence indicator has been specified:

-----------------------------------------------------
[Expr cast as AtomicType ]
  ==
  let $v as xs:anyAtomicType := fn:data(([ Expr ]Expr)) return
    $v cast as AtomicType
 
  [Expr cast as AtomicType? ]Expr
  ==
  let $v as xs:anyAtomicType? := fn:data(([ Expr ]Expr)) return
    typeswitch ($v)
      case $fs:new as empty-sequence() return ()
      default $fs:new return $v cast as AtomicType
-----------------------------------------------------

I suspect many implement an inference that takes into account whether the operand&apos;s static type&apos;s cardinality allows the empty sequence(I know at least two impls.), and for that reason we receive these reports first now.

I think it would be sensible to make &apos;cast as&apos; smarter here(FS change) because it would make static typing behave as non-static typing in the reported cases. People expect passing xs:foo(&quot;value&quot;) to work, because it&apos;s XPath&apos;s way of creating literals for some values.

Of course, this is only a fix when the arguments to functions are cast expressions, but I can&apos;t come to think of other cases(well, there surely are, but the question is how widely used).


Frans</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11604</commentid>
    <comment_count>7</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2006-09-11 08:08:58 +0000</bug_when>
    <thetext>Yes.

Am I correct in thinking that all built-in type constructors called with a parameter of type anyAtomicType which is a non-empty sequence will either throw an error (because the form of the input is in some way wrong) or return a value of that type?  If so, the type rules:

statEnv |-  QName of func in { set of built-in constructors }
statEnv |-  Expr : empty 
-------------------------------------------------------------
statEnv  |-  QName(Expr) : empty

statEnv |-  QName of func in { set of built-in constructors }
statEnv |-  Expr : Type      quantifier(Type) in { 1 }
-------------------------------------------------------------
statEnv  |-  QName(Expr) : Type

should clear up many of the problems we&apos;ve highlighted.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11645</commentid>
    <comment_count>8</comment_count>
    <who name="Frans Englich">frans.englich</who>
    <bug_when>2006-09-13 11:43:22 +0000</bug_when>
    <thetext>Answering your question: yes, I believe so(not taking into account any type/dynamic errors in the operand or its children, of course).

However, I don&apos;t think the suggested inference rules in #7 would work because constructor functions are mapped to &apos;cast as&apos; expressions. Therefore, I believe the inference rules-changes need to be done for &apos;cast as&apos;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11894</commentid>
    <comment_count>9</comment_count>
    <who name="Andrew Eisenberg">andrew.eisenberg</who>
    <bug_when>2006-09-20 20:45:45 +0000</bug_when>
    <thetext>There is the larger question of the inferred static type of constructor functions that has been brought to the WGs in 3717.

For the several test cases mention in this report, however, a simple fix is to remove the xs:string constructor function.

The query:

   fn:matches(xs:string(&quot;This is a characte&quot;),xs:string(&quot;This is a characte&quot;))

can be rewritten as

   fn:matches(&quot;This is a characte&quot;,&quot;This is a characte&quot;)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>12042</commentid>
    <comment_count>10</comment_count>
    <who name="Carmelo Montanez">carmelo</who>
    <bug_when>2006-09-26 14:52:51 +0000</bug_when>
    <thetext>All:

Corrected the static typing failures by remving the constructor functions.
The replace tests were generated automatially and it seems as though
they are similar.  When time allows, I will make the tests match the documentation.

Thanks,
carmelo</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>