Artifacts Associated With Ticket 6ee2f5d5d6bc7d69
Ticket change [8b5636d366] (rid 255071) by jdelsign on 2026-07-29 20:20:21:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-plain"
- comment initialized to:
I am in the process of upgrading from Tcl 8.6.14 to Tcl 9.0.4. The following commands produce an error in Tcl 9.0.4, but it was OK in Tcl 8.6.14. $ tclsh % set tcl_patchLevel 9.0.4 % set a("b") x x % array names a {"b"} % set a(b) y y % array names a b {"b"} % puts $a(b) y % puts $a("b") invalid character in array index % Why is that an error in Tcl 9.0.4? The workaround I have been using is to access the value using set: % set a("b") x % - foundin initialized to: "9.0.4"
- is_private initialized to: "0"
- login: "jdelsign"
- priority initialized to: "5 Medium"
- private_contact initialized to: "cda79e7c26c7aaa8a79a31b5a67382ef3b84d2c9"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "jdelsign"
- subsystem initialized to: "07. Variables"
- title initialized to:
Tcl 9.0 "invalid character in array index" error for $a("b") - type initialized to: "Bug"
Ticket change [cf6af92bec] (rid 255072) by apnadkarni on 2026-07-30 02:37:13:
- icomment:
It appears this is a result of [TIP 465](https://core.tcl-lang.org/tips/doc/trunk/tip/465.md). To quote, *Generally disallowing bare open parens, quotes and braces within array indices would mean that array indices on left hand side of an assignment could follow same rules as on right hand side* The motivation seems to have been TIP 282, which however has never come to a vote. I wasn't privy to the original discussions so can't comment further. Leaving it to those who were to decide whether this is a bug or close as works-as-designed.
- login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [26fdfe8b34] (rid 255073) by oehhar on 2026-07-30 09:04:34:
- icomment:
Yes, special characters have to be escaped. <verbatim> % set a("b") x x (bin) 2 % puts $a(\"b\") x </verbatim> I remeber a long discussion on this... Perhaps, Andreas may comment on this. And we may enhance the migration notes by examples. Thanks for all, Harald - login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [65e121a697] (rid 255074) by avl42 on 2026-07-30 09:11:24:
- icomment:
This is a necessary regression that had to happen at a major version shift, to pave the way for some extension in expr lateron. The change does not affect setting of variables, but it affects specifically the syntax for retrieving array-elements. In tcl 8 you could also do weird things like puts $a(((), if "((" was among the keys in the array; but no longer in Tcl 9. Btw., the following variants continue to work: # escaping the special characters, if they need to be given literally: puts $a(\"b\") set a((() z; puts $a(\(\() # any chars can still be used via substitution: set key {"b"}; puts $a($key) foreach k [array names a] {puts "$k: $a($k)"} - login: "avl42"
- mimetype: "text/plain"
- username: "avl"
- icomment:
Ticket change [ca6fd69dbe] (rid 255075) by apnadkarni on 2026-07-30 09:25:25:
- closedate changed to: "2461251.8926614933"
- closer changed to: "apnadkarni"
- icomment:
Thanks, @avl42, @oehhhar, closing then as works as designed.
- login: "apnadkarni"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Closed"
Ticket change [a2a07bc99f] (rid 255076) by oehhar on 2026-07-30 09:48:58:
- closedate changed to: "2461251.9090100462"
- closer changed to: "oehhar"
- icomment:
Perhaps we can enhance the text in the migration guide: [https://core.tcl-lang.org/tcl/wiki?name=Migrating+scripts+to+Tcl+9&p] For me, this is not cristal clear in the TIP or migration guide, as it only speaks about "{" and "(" and not about '"' and "\". And it is not only about referencing: <verbatim> % set a(\) x x % array names a {} </verbatim> So, in array creation, any trailing "\" was stripped from the index without an error. This is probably a bug but anyway. In 9.0, the set causes an error. - login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
Ticket change [bdab65cc3e] (rid 255077) by oehhar on 2026-07-30 10:01:19:
- closedate changed to: "2461251.9175885879"
- icomment:
Single backslash in variable name resolution also workes with 8.6: <verbatim> % set \\ x x % puts ${\} x </verbatim> On referencing with variables, a single "\" is taken as verbatim. On referencing with array indexes, a single "\" is stripped away. And this is also interesting with 9.0.4: <verbatim> % set \\ x x % puts ${\\} can't read "\\": no such variable % puts $\\ $\ </verbatim> So, a $\\ is verbatim interpreted - very interesting... There is no more verbatim way to express a variable name of "\"... Thanks for all, Harald - login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
Ticket change [d83f786691] (rid 255079) by oehhar on 2026-07-30 10:25:20:
- closedate changed to: "2461251.9342602664"
- icomment:
[e210f2ad2c] is proposed to enhance migration guide. Thanks for all, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
Ticket change [368d335146] (rid 255080) by oehhar on 2026-07-30 10:26:22:
- closedate changed to: "2461251.9349873266"
- icomment:
Grr, here is the correct changes link [https://core.tcl-lang.org/tcl/wdiff?id=e210f2ad2cfea078]
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
Ticket change [4c023bfba7] (rid 255081) by avl42 on 2026-07-30 15:23:05:
- closedate changed to: "2461252.1410410646"
- closer changed to: "avl42"
- icomment:
Hello again... The syntax for ${...} is still VERY odd, and that wasn't addressed/changed in that TIP, because it didn't cross the plans for assignment in expr. It is still as odd as it was in 8.x, and it only becomes more odd, if you have puts ${\} inside a braced block... try it... you'll be in for some surprises, if you even try, unless you have really really really understood the dodekalogue of Tcl syntax. ;-) Regarding set a(\) x then the "set" command only sees "a()" and "x" as its arguments, and never even saw the backslash there. - login: "avl42"
- mimetype: "text/plain"
Ticket change [164c01ff2e] (rid 255082) by oehhar on 2026-07-30 18:45:48:
- closedate changed to: "2461252.2818114697"
- closer changed to: "oehhar"
- icomment:
Thanks, great. With the "set a(\) x" I just wanted to say, that this changed from 8.6 to 9.0. So it is not only referencing via dollar, but also setting. Do you like my new migration notes? THanks, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
Ticket change [21856fa4b0] (rid 255083) by avl42 on 2026-07-30 18:48:20:
- closedate changed to: "2461252.2835694561"
- closer changed to: "avl42"
- icomment:
Sorry, I've got to chime in again, but nothing changed in that case: set a(\) x already did exactly the same thing in Tcl 8.x
- login: "avl42"
- mimetype: "text/plain"
Ticket change [a4a550a21b] (rid 255084) by avl42 on 2026-07-30 19:37:23:
- closedate changed to: "2461252.3176303124"
- icomment:
And one more thing: I also made a mistake in the comments below: I had totally forgotten that ${...} indeed also got sanitized (de-"odd"ed) between tcl-8.x and tcl 9.0. Sorry about that. I've also had a look at your(oehhar) changes: yes, they're fine and correct, except maybe for the last line regarding symmetry to expr... symmetry is not the thing here... Discussion back then came to the result that those tcl-8's odd-balls regarding $arr(...) and ${...} would just spoil all attempts at making something like [expr {a(((()=42+12}] a consistent parse. Maybe "consistency" would be a preferred wording w.r.t the changes and "expr". - login: "avl42"
- mimetype: "text/plain"
Ticket change [2138b8f2cb] (rid 255085) by oehhar on 2026-07-31 08:31:59:
- closedate changed to: "2461252.8555512615"
- closer changed to: "oehhar"
- icomment:
Ok, great. symetry->consistency changed. Thanks for all, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"