diff options
-rw-r--r-- | generic/tclListObj.c | 15 | ||||
-rw-r--r-- | tests/list.test | 7 |
2 files changed, 16 insertions, 6 deletions
diff --git a/generic/tclListObj.c b/generic/tclListObj.c index 0852c8c..362efa2 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -1827,11 +1827,6 @@ SetListFromAny( List *listRepPtr; Tcl_Obj **elemPtrs; - /* - * Dictionaries are a special case; they may have stored a previous list - * representation - */ - listPtr = TclObjLookupTyped(objPtr, &tclListType); if (listPtr != NULL) { Tcl_IncrRefCount(listPtr); @@ -1844,7 +1839,15 @@ SetListFromAny( return TCL_OK; } - if (objPtr->typePtr == &tclDictType) { + /* + * Dictionaries are a special case; they have a string representation such + * that *all* valid dictionaries are valid lists. Hence we can convert + * more directly. Only do this when there's no existing string rep; if + * there is, it is the string rep that's authoritative (because it could + * describe duplicate keys). + */ + + if (objPtr->typePtr == &tclDictType && !objPtr->bytes) { Tcl_Obj *keyPtr, *valuePtr; Tcl_DictSearch search; int done, size; diff --git a/tests/list.test b/tests/list.test index dff5d50..661ddde 100644 --- a/tests/list.test +++ b/tests/list.test @@ -129,6 +129,13 @@ test list-4.1 {Bug 3173086} { string is list "{[list \\\\\}]}" } 1 +test list-5.1 {list/dict conversions without} { + set a {a 1 a 2} + dict get $a a + lindex $a 1 +} 1 + + # cleanup ::tcltest::cleanupTests return |