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

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





------- Comment #1 from frans.englich@telia.com  2006-03-12 12:31 -------

Proposed wording of the definition for effective case:

[Definition: The effective case in a typeswitch expression is the case
whose SequenceType matches the value of the operand expression, using the rules
of SequenceType matching. If more than one SequenceType matches, the matching
case appearing first in the query is the effective case.]

It can surely be improved. Nevertheless, I think it makes it clear that the
query:

typeswitch((1, 2, "a string"))
    case item+ return 1
    case xdt:anyAtomicType+ return 2
    default return 3

evaluates to 1. One could add the query as an example; it illustrates what that
is chosen in case multiple cases matches, and that the value of the operand
expression is treated as a whole, not on a per-item basis.

Another possibility is to require implementations to determine the closest
matching case. But I ruled it out because it hinders exit-early optimizations
for the gain of the in practice rare case(my speculation) where the user
specifies multiple matching cases, in an order where the first matching would
be wrong, from the user's perspective.


One could make it an error if a case specifies a sequence type that is a sub
type of a sequence type appearing before it, because it will never match(the
user's code makes no sense, it is buggy). The advantage is that it wouldn't be
possible to write a typeswitch where it is in any way vague what case branch is
taken. It would be a typical warning an implementation could issue, but perhaps
it is useful enough for making the spec require it. But, the additional
implementation burden and that the user's code is dealt with on such a low
level, makes it doubtful. But I mention it.


Frans

Received on Sunday, 12 March 2006 12:31:31 UTC