Skip to content
Tcl Source Code View Ticket
Login

View Ticket

[switch] accepts illegal arguments

Closed / Fixed475397ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 25 years ago
Descriptionplain2001-10-26 18:36:11
$ tclsh
% switch a a {} c
% switch a [list a {} c]

Both examples are illegal
calls of [switch] because
they include a pattern
without a body, but neither
raises an error.

An error should be raised in
each case.
dgpplain2001-10-27 03:51:46
Logged In: YES 
user_id=80530

Note also

switch a {a {} default -}
vs
switch b {a {} default -}


and

switch a {a {} b -}
vs.
switch b {a {} b -}

The common thread is that errors aren't caught
until an attempt to evaluate them is made.

Finally, note the inconsistency of

switch a
and
switch a {}

The man page for switch say both should
raise an error.  I'd be happier if both
were successful no-ops.
dkfplain2001-11-27 20:33:54
Logged In: YES 
user_id=79902

I've fixed all these and made the behaviour consistent
between when the arms are done as separate arguments and
when they are a list, though I've tightened up in favour of
making [switch a {}] produce an error as that is consistent
with the documentation.
Log in (anonymous is fine) to add a comment.