#5222 copied object member variable confusion

current: 8.6.0
open
8
2013-04-01
2013-04-01
Poor Yorick
No

In the following script, $obj2 thinks the value of its $var1 is "val1"

namespace import oo::*
set obj [object new]
objdefine $obj variable var1
objdefine $obj method m {} {
set var1 val1
}
objdefine $obj method get {} {
return $var1
}

$obj m
$obj get
set obj2 [oo::copy $obj]
${obj2}::my eval {
set var1 val2
}
puts [$obj2 get]

Discussion

  • Donal K. Fellows

    Looks like there's a cached reference to the variable in the method implementation, which is indeed the case because that's how variable references in object-specific methods are bound. The method cloner needs work...

     
  • Donal K. Fellows

    • priority: 5 --> 8
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks