[Bug 2999] typeswitch: how to handle case clauses specifying the same type

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

           Summary: typeswitch: how to handle case clauses specifying the
                    same type
           Product: XPath / XQuery / XSLT
           Version: Candidate Recommendation
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XQuery
        AssignedTo: chamberl@almaden.ibm.com
        ReportedBy: frans.englich@telia.com
         QAContact: public-qt-comments@w3.org


>From what I can tell, the following query succeeds to compile:

    typeswitch(1)
        case xs:integer return 1
        case xs:integer return 2
        default return -1

What it evaluates to, I find more tricky to determine. I think this sentence is
supposed to tell:

<quote>
[Definition: The effective case in a typeswitch expression is the first case
clause such that the value of the operand expression matches the SequenceType
in the case clause, using the rules of SequenceType matching.
</quote>

I find the sentence phrased in a tricky way("the first case clause such that
the value of"). I assume that the "first case" refers to the first case clause
in terms of occurrence in the "physical" query, not whatever the
implementations happens to match "first".

I think the above query should fail to compile because it is vague what is the
result, and it is unclear what the user wants should happen. Other languages,
such as C++, treats identical case conditions as errors. Perhaps this applies
extraordinarily due to the declarative nature of XQuery and its lack of "order
of execution".

More specifically, I propose two things:

* That the following paragraph is added: "It is an error if two or more case
clauses specifies sequence types that are identical to one another[new error
code].", or something in that direction. I don't know what to refer to in order
to define sequence type equalness(probably something in 2.5.4). Perhaps one
should keep an eye on that it is clear that types can still have the same
parent types(it sounds perhaps obvious since all types are derived from item()
if one thinks about it, but then one have to think about it).

* Reword the definition of effective case to be a bit simpler(or is it just
me?)

However, I do suspect I've missed something glaringly obvious..


Regards,
Frans

Received on Saturday, 11 March 2006 19:47:22 UTC