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.
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)
(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.
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)
The Working Group affirmed the wording in Comment #6 today.