Skip to content
Tcl Source Code View Ticket
Login

View Ticket

regression in compiled [unset]

Closed / Fixed3970f54c4e96d126454688cee820e6808d623918Created 13 years agoUpdated 11 years ago
Descriptionplain2013-09-19 18:07:57
In Tcl 8.5:

% apply {{} {unset foo [return 1]}}
1

In Tcl 8.6(.1):

% apply {{} {unset foo [return 1]}}
can't unset "foo": no such variable

The compiler for [unset] is failing to
preserve substitution ordering rules.
Referenced by2
  • af5c35971a[3970f54c4e]: Improved fix that is more tolerant of a single variable varname. check-in2013-09-19 22:37:06
  • 836d61598d[3970f54c4e]: Corrected regression in argument order processing in [unset]. check-in2013-09-19 19:37:05
dgpplain2013-09-19 18:44:38
Passing to the author of TclCompileUnsetCmd().
dkf Ticket [3970f54c4e]: 3 changes [History diff]2013-09-19 19:10:38
dkfhtml2013-09-19 19:41:53

Yes, that was a bug. Sorted it by making the compiler stricter in what it handles, which shouldn't be a problem for most code.

I need to figure out a better way to handle what happens when unsetting a single variable with a non-literal specifying the name; that's a case which ought to work in principle, but which the current restriction stops. But in any case, current behavior is semantically correct; this doesn't block a release now.

dkfhtml2013-09-19 22:43:18

Thinking about it, we can handle a single variable varName provided it is the first varName and either there was an option (-- or -nocomplain) beforehand, or the varName provably doesn't begin with a hyphen.

Determining the latter in the presence of a non-constant word is messy (check if you've got a TCL_TOKEN_WORD with a leading TCL_TOKEN_TEXT whose first char is a non-hyphen) as there's now convenient function for this. Nor would there be; it's specialised!

Applied this version. Still passes the test case, but also compiles unset foo($bar) fine (verified by disassembly).

dgpplain2015-07-17 19:40:04
Postscript: The compiled [unset foo($bar)] here is leaking memory.

http://core.tcl.tk/tcl/tktview/a3309d01db
dgpplain2015-07-17 20:30:22
It appears that the handling of options is off as well,
but that's hard to figure out because the handling is very
poorly specified.
dgpplain2015-07-17 20:55:26
The direct eval and the compiled [unset] do not
agree on what this should mean:

    unset -nocomplain --
dgpplain2015-07-18 05:51:42
Now they do again.
Log in (anonymous is fine) to add a comment.