You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ cat noClassVars.tcl
# test for "can't unset __" bug in oo.tcl.
package require oo
class d {}
d method ok {} {puts ok}
set n [d new]
$n ok
$ ./jimsh noClassVars.tcl
oo.tcl:72: Error: can't unset "__": no such variable
in procedure '<reference.<d______>.00000000000000000000>' called at file "noClassVars.tcl", line 6
in procedure 'd ok' called at file "oo.tcl", line 52
at file "oo.tcl", line 72
Rate of occurrence: 100%.
patch:
diff --git a/oo.tcl b/oo.tcl
index b6ad4a9..d609469 100644
--- a/oo.tcl
+++ b/oo.tcl
@@ -69,7 +69,7 @@ proc class {classname {baseclasses {}} classvars} {
# Note that we can't use 'dict with' here because
# the dict isn't updated until the body completes.
foreach __ [$self vars] {upvar 1 instvars($__) $__}
- unset __
+ if {[exists __]} {unset __}
eval $__body
}
}
new result:
$ cat noClassVars.tcl
# test for "can't unset __" bug in oo.tcl.
package require oo
class d {}
d method ok {} {puts ok}
set n [d new]
$n ok
$ ./jimsh noClassVars.tcl
ok
catch {unset __} works too, but might be slower due to another stack frame. Speed is relevant in that spot.
If that behavior was chosen e.g. for performance reasons, it wasn't documented at all. This patch makes it conform to the documented behavior (and the handier behavior), which I'd prefer.
result in version 0.79:
Rate of occurrence: 100%.
patch:
new result:
catch {unset __}
works too, but might be slower due to another stack frame. Speed is relevant in that spot.If that behavior was chosen e.g. for performance reasons, it wasn't documented at all. This patch makes it conform to the documented behavior (and the handier behavior), which I'd prefer.
@msteveb shall I open a pull request?
The text was updated successfully, but these errors were encountered: