summaryrefslogtreecommitdiffstats
path: root/generic/tclDictObj.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2019-04-01 10:38:47 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2019-04-01 10:38:47 (GMT)
commit8d4509eafc4ae6d4ebc12d6b08180fca038bdf8f (patch)
tree58763149bab01eaf7f9bce9114c6a59c2becbdfc /generic/tclDictObj.c
parentd2fb211d208690336c1cc183cbd4c8d488411ff2 (diff)
downloadtcl-8d4509eafc4ae6d4ebc12d6b08180fca038bdf8f.zip
tcl-8d4509eafc4ae6d4ebc12d6b08180fca038bdf8f.tar.gz
tcl-8d4509eafc4ae6d4ebc12d6b08180fca038bdf8f.tar.bz2
Add tests
Diffstat (limited to 'generic/tclDictObj.c')
-rw-r--r--generic/tclDictObj.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/generic/tclDictObj.c b/generic/tclDictObj.c
index c312242..75dcd09 100644
--- a/generic/tclDictObj.c
+++ b/generic/tclDictObj.c
@@ -1658,7 +1658,7 @@ DictGetWithDefaultCmd(
int numKeys;
if (objc < 4) {
- Tcl_WrongNumArgs(interp, 1, objv, "dictionary ?key ...? key value");
+ Tcl_WrongNumArgs(interp, 1, objv, "dictionary ?key ...? key default");
return TCL_ERROR;
}
@@ -1668,7 +1668,8 @@ DictGetWithDefaultCmd(
dictPtr = objv[1];
keyPath = &objv[2];
- numKeys = objc - 4;
+ numKeys = objc - 4; /* Number of keys in keyPath; there's always
+ * one extra key afterwards too. */
keyPtr = objv[objc - 2];
defaultPtr = objv[objc - 1];
@@ -1677,9 +1678,11 @@ DictGetWithDefaultCmd(
*/
dictPtr = TclTraceDictPath(interp, dictPtr, numKeys, keyPath,
- DICT_PATH_READ);
+ DICT_PATH_EXISTS);
if (dictPtr == NULL) {
return TCL_ERROR;
+ } else if (dictPtr == DICT_PATH_NON_EXISTENT) {
+ Tcl_SetObjResult(interp, defaultPtr);
} else if (Tcl_DictObjGet(interp, dictPtr, keyPtr, &valuePtr) != TCL_OK) {
return TCL_ERROR;
} else if (valuePtr == NULL) {