Skip to content

Commit b733648

Browse files
committed
Stop variable from disappearing by accident when referred to by name. [74b6110204]
2 parents d4a730f + 7cb0865 commit b733648

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

generic/tclOOBasic.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,11 @@ TclOO_Object_VarName(
826826
return TCL_ERROR;
827827
}
828828

829+
/*
830+
* The variable reference must not disappear too soon. [Bug 74b6110204]
831+
*/
832+
TclSetVarNamespaceVar(varPtr);
833+
829834
/*
830835
* Now that we've pinned down what variable we're really talking about
831836
* (including traversing variable links), convert back to a name.

tests/oo.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,20 @@ test oo-19.3 {OO: varname method and variable decl: Bug 3603695} -setup {
30553055
} -cleanup {
30563056
testClass destroy
30573057
} -result 0
3058+
test oo-19.4 {OO: varname ghosts [Bug 74b6110204]} -setup {
3059+
oo::class create testClass {
3060+
export varname
3061+
self export createWithNamespace
3062+
}
3063+
set obj [testClass createWithNamespace testoo19_4 testoo19_4]
3064+
set ns [info object namespace $obj]
3065+
} -body {
3066+
set v [$obj varname foo]
3067+
list [namespace which -variable $v] \
3068+
[info exists $v] [namespace which -variable $v]
3069+
} -cleanup {
3070+
testClass destroy
3071+
} -result {::testoo19_4::foo 0 ::testoo19_4::foo}
30583072

30593073
test oo-20.1 {OO: variable method} -body {
30603074
oo::class create testClass {

0 commit comments

Comments
 (0)