Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oo errors with no class variables #148

Closed
The-Markitecht opened this issue Feb 5, 2020 · 1 comment
Closed

oo errors with no class variables #148

The-Markitecht opened this issue Feb 5, 2020 · 1 comment

Comments

@The-Markitecht
Copy link
Contributor

result in version 0.79:

$ 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.

@msteveb shall I open a pull request?

@msteveb
Copy link
Owner

msteveb commented Feb 5, 2020

Yes please. I suggest unset -nocomplain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants