Artifacts Associated With Ticket 7cea8bfad06c3f18
Ticket change [e2d2d51362] (rid 223210) by sethrader on 2024-03-17 17:31:11:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-markdown"
- comment initialized to:
Running the following code will produce an error on attempting to declare a variable "h": ``` #!/usr/bin/env tclsh proc p {} { variable d {a 0} dict for {key h} $d {} variable h "Should not be set already" } p ``` Note: this only seems to occur in the body of a procedure. The code inside proc "p" will execute fine if executed outside a procedure body. Platform: Linux/Tcl 8.6.14 Could not replicate the same issue on Tcl 8.6.13 under Wine - foundin initialized to: "8.6.14"
- is_private initialized to: "0"
- login: "sethrader"
- priority initialized to: "5 Medium"
- private_contact initialized to: "0ae952f0c697d54d4d2c5ee3f3c3968bce95854e"
- resolution initialized to: "None"
- severity initialized to: "Critical"
- status initialized to: "Open"
- submitter initialized to: "sethrader"
- subsystem initialized to: "15. Dict Object"
- title initialized to:
[dict for] does not clean up "value" var name after execution
- type initialized to: "Bug"
Ticket change [86214e5628] (rid 223221) by sethrader on 2024-03-18 01:51:32:
- login: "sethrader"
- mimetype: "text/plain"
- title changed to:
[dict for] "value" var name escapes code block scope
Ticket change [15d77ab401] (rid 223222) by apnadkarni on 2024-03-18 04:47:37:
- icomment:
I don't understand the bug. Seems to me expected behavior. Why would you expect h to not be set? The dict for executes in the same scope as the containing code and introduces variables in that scope. With respect to difference in behavior between proc and global cases, that has nothing to do with the dict command. ``` % set foo 1 1 % variable foo % proc xx {} {set x 1; variable x} % xx variable "x" already exists % namespace eval ns {set z 1; variable z} % ``` Note only the proc case generates an error, not the global or namespace cases, because the command has different semantics inside a proc. At the global or namespace level, the command creates a variable. Within a proc, `variable` creates a *link* to the variable of that name in the containing namespace. Linked variables are not allowed if a variable of that name already exists. You can see this with upvar as well. ``` % set v 1 1 % proc yy {} {set x 1; upvar v x} % yy variable "x" already exists ``` I see the same behavior with Tcl 8.6.13 on Windows as 8.6.14. As to why you do not see the error with 8.6.13 on Wine, no idea. ``` % proc p {} { variable d {a 0} dict for {key h} $d {} variable h "Should not be set already" } % p variable "h" already exists % package require Tcl 8.6.13 ``` - login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [3417ff3d93] (rid 223233) by sethrader on 2024-03-18 09:57:47:
- icomment:
I apologize, I had simplified the actual code where the discrepancy was taking place in order to have a refined example, and mistook what I thought was a bug as the cause of the discrepancy. After simplifying the code, I neglected to check it again in 8.6.13. Now that I have reviewed the code, I realize that the discrepancy is not due to version differences in Tcl but differences in the environment I was executing in. Specifically, a configuration file was being read under wine that set the initial dictionary (d) to an empty dictionary, so `h` would never have been set. Again, sorry for the inconvenience. Please close this ticket.
- login: "sethrader"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [276a9829cc] (rid 223234) by sethrader on 2024-03-18 10:00:50:
- closedate changed to: "2460387.91725204"
- closer changed to: "sethrader"
- login: "sethrader"
- mimetype: "text/plain"
- status changed to: "Closed"
Ticket change [d381cb8857] (rid 223235) by sethrader on 2024-03-18 10:02:00:
- closedate changed to: "2460387.91806543"
- login: "sethrader"
- mimetype: "text/plain"
- resolution changed to: "Invalid"