[Bug 2789] Substitutability of duration subtypes

http://www.w3.org/Bugs/Public/show_bug.cgi?id=2789

           Summary: Substitutability of duration subtypes
           Product: XPath / XQuery / XSLT
           Version: Candidate Recommendation
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Functions and Operators
        AssignedTo: ashok.malhotra@oracle.com
        ReportedBy: mike@saxonica.com
         QAContact: public-qt-comments@w3.org


Frans Englich posted as follows on the mulberry xsl-list yesterday:

<quote>
Saxon 8.6 fails this expression with XPTY0004, "Cannot compare 
xdt:yearMonthDuration to xs:duration":

xdt:yearMonthDuration("P200Y2M") eq xs:duration("P200Y2M")


The XPath 2.0 book specifies these operators:

A eq B  xdt:yearMonthDuration     xdt:yearMonthDuration  
A eq B  xdt:dayTimeDuration  	  xdt:dayTimeDuration  
A eq B  xs:duration               xs:duration

It also says this:

<quote>
Any operator listed in the operator mapping tables may be validly applied to 
an operand of type AT if the table calls for an operand of type ET and 
type-matches(ET, AT) is true (see 2.5.4 SequenceType Matching). For example, 
a table entry indicates that the gt operator may be applied to two xs:date 
operands, returning xs:boolean. Therefore, the gt operator may also be 
applied to two (possibly different) subtypes of xs:date, also returning 
xs:boolean.
</quote>

Doesn't type-matches(xs:duration, xdt:yearMonthDuration) hold true? My point 
being that the expression should succeed because xdt:yearMonthDuration is a 
subtype of xs:duration and that the xs:duration-eq operator therefore can be 
applied. If that is the case, which I doubt, the eq/ne operators for the two 
XDT durations are redudant, since the xs:duration-eq/ne operators covers 
them.

What clause in any of the specifications disallow the above operand 
combination? (and the others variations by the same principle)
</quote>

I think Frans has a good point here. op:duration-equal is defined as

if (cast as xdt:yearMonthDuration ($arg1) eq
      cast as xdt:yearMonthDuration($arg2) 
   and
      cast as xdt:dayTimeDuration($arg1) eq 
      cast as xdt:dayTimeDuration ($arg2)) return fn:true()
  else return fn:false()

and this produces the correct result for any combination of duration,
dayTimeDuration, and yearMonthDuration.

So I think we should remove the four lines in the operator mapping table that
define eq and ne operations between subtypes of duration, and the corresponding
functions op:dayTimeDuration-equal and op:yearMonthDuration-equal.

Michael Kay

Received on Wednesday, 1 February 2006 12:45:30 UTC