Tcl Source Code

View Ticket
Login
Ticket UUID: d22ad202055093292992c6aea053188f8b3d4abe
Title: "dict unset d key subkey" fails if key does not exist
Type: Bug Version: >= 8.5
Submitter: oehhar Created on: 2018-07-02 10:24:28
Subsystem: 15. Dict Object Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2020-11-16 14:19:43
Resolution: Fixed Closed By: oehhar
    Closed on: 2020-11-16 14:19:43
Description: (text/x-fossil-wiki)
If a dictionary key is unset, there is no error, if it does not exist:

<verbatim>
% set d {}
% dict unset d a
</verbatim>

<hr />

There is an error raised, if a key on the path of the subkey does not exist:

<verbatim>
% set d {}
% dict unset d a b
key "a" not known in dictionary
</verbatim>

IMHO this is inconsistent and should not rise an error.

At least the documentation should write about error behaviour.

<hr />

I can understand, that an error is raised, if the (sub)dict is not a valid dict.

<verbatim>
% set d {1}
% dict unset d a
missing value to go with key
% set d {a 1}
% dict unset d a b
missing value to go with key
</verbatim>
User Comments: oehhar added on 2020-11-16 14:19:30: (text/x-fossil-wiki)
Tested again with tcl8.6.10. Is fixed. Thank you, Harald

sebres added on 2018-07-02 11:03:13: (text/x-fossil-wiki)
Still worse (as regards the inconsistency), it does not produce any error if dictionary self (variable) does not exists:

<code><verbatim>
% unset -nocomplain d
% catch { dict unset d a }
0
</verbatim></code>

So I'm agree with Harald's conclusion, the `dict unset` must not produce an error if sub-key does not exists also.