Bug 20632 - [XP 3.0] Transitivity of subtype relationships
Summary: [XP 3.0] Transitivity of subtype relationships
Status: RESOLVED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XPath 3.0 (show other bugs)
Version: Last Call drafts
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Jonathan Robie
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-10 12:33 UTC by Michael Kay
Modified: 2013-01-29 16:28 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Kay 2013-01-10 12:33:59 UTC
I think we would all agree that there is a fundamental principle that subtyping relationships need to be transitive: A<:B and B<:C implies A<:C. Sadly this is not currently true of the subtyping rules for union types.

According to the current rules, subtype(xs:decimal, union(xs:decimal, xs:string)) is true, and subtype(xs:integer, xs:decimal) is true, but subtype(xs:integer, union(xs:decimal, xs:string)) is false.

This is clearly an oversight and should be fixed.
Comment 1 Michael Kay 2013-01-11 10:03:49 UTC
The relevant rules are these two:

1. Ai and Bi are AtomicOrUnionTypes, and derives-from(Ai, Bi) returns true.

2. Ai and Bi are both pure union types, and every type t in the transitive membership of Ai is also in the transitive membership of Bi.

If we fix bug #20643, then the meaning of rule 1 changes, and subtype(xs:integer, union(xs:decimal, xs:string)) becomes true. This fixes part of the problem.

The other part of the problem is that union(a, b) should be a subtype of union(A, B) if a is a subtype of A and b is a subtype of B. We can achieve this by changing rule 2 to say:

2. Ai is a pure union type, and every type t in the transitive membership of Ai satisfies subtype-itemType(t, Bi)

However, this has a side-effect which we may or may not consider desirable. The side-effect is that (for example) union(dayTimeDuration, yearMonthDuration) is now a subtype of duration, which was not the case before. Clearly it is both safe and useful that this relation should hold, but it is definitely a change in the spec. If we want to avoid introducing this side-effect, we could instead write rule 2 as:

2. Ai and Bi are both pure union types, and every type t in the transitive membership of Ai satisfies subtype-itemType(t, Bi)
Comment 2 Tim Mills 2013-01-20 08:54:32 UTC
(In reply to comment #1)
> The relevant rules are these two:
> 
> However, this has a side-effect which we may or may not consider desirable.
> The side-effect is that (for example) union(dayTimeDuration,
> yearMonthDuration) is now a subtype of duration, which was not the case
> before. 

I believe that, according to Formal Semantics, this was always the case, so shouldn't be regarded as a change, since for every value V that matches the union, V also matches duration.  So I'd argue it was true in XQ1.0.
Comment 3 Jonathan Robie 2013-01-22 17:03:45 UTC
The Working Group decided to change the second of these two rules (the first two rules in the list under 2.5.6.2 The judgement subtype-itemtype(Ai, Bi)):

<quote>
1. Ai and Bi are AtomicOrUnionTypes, and derives-from(Ai, Bi) returns true.

2. Ai and Bi are both pure union types, and every type t in the transitive membership of Ai is also in the transitive membership of Bi.
</quote>

The new wording for the second rule is:

2. Ai is a pure union type, and every type t in the transitive membership of Ai satisfies subtype-itemType(t, Bi)
Comment 4 Jonathan Robie 2013-01-29 16:28:48 UTC
The Working Group affirmed the wording in Comment #6 today.