|
2026-10-22
| ||
| 17:19 | • Ticket [4af2f209f2] oo::define variable status still Closed with 3 other cha... artifact: f029ff4098 user: serhiy.storchaka | |
|
2026-10-15
| ||
| 11:29 | • Closed ticket [4af2f209f2]. artifact: bc9bb61a4d user: serhiy.storchaka | |
|
2024-09-17
| ||
| 08:42 | • Pending ticket [4af2f209f2]. artifact: cdf4d94d2d user: dkf | |
|
2016-08-20
| ||
| 15:53 | • Ticket [4af2f209f2]: 5 changes artifact: 97b9725b31 user: dkf | |
|
2016-01-17
| ||
| 13:43 | • Ticket [4af2f209f2]: 4 changes artifact: d9649e06af user: aspect | |
|
2016-01-16
| ||
| 18:00 | • Ticket [4af2f209f2]: 3 changes artifact: ad61276f6f user: aku | |
| 09:22 | • New ticket [4af2f209f2]. artifact: 1e8d57e2c7 user: anonymous | |
oo::define variable
This next example doesn't work.
oo::class create c {
constructor {} {
oo::define [self class] variable var1
set var1 something
}
method x {} {
puts $var1
}
}
c create a
a x
Playing around with this a little further, the quirk seems to be in how variables behave that are added to a class while a method is running.
oo::class create D {
method a {} {
oo::define [self class] variable var
puts [namespace which -variable var]\t[incr var]
}
}
D create b
b a
# ::oo::Obj12::var 1
b a
# ::oo::Obj12::var 1
b a
# ::oo::Obj12::var 2
According to [namespace which] and [info vars], $var immediately refers to the instance variable. But that wasn't the case when the first call to [b a] was entered, so (it seems) incrScalar1Imm hits a local.
Inhibiting compilation of [incr var] changes the behaviour -- TclIncrObj finds the instance variable each time.
Adjusting the variable resolver's rules on a class from within a running method constructor? Yuck. There's literally no way to make that nice and reliable without slowing ordinary code down. The core issue is that compiled variables are resolved earlier, during the creation of the stack frame (with some magic caching to speed it up), but when there's a direct lookup by name that's done through the resolver anyway. Since the resolver is by design expensive and reliant on compilation for speed, there's no way we want to bring it in on every variable access. There's a minor issue that we could fix things by doing a bytecode flush when the resolver is changed... but it is such a nasty edge case. There's really no good reason to do this that I can think of and there are trivial workarounds (e.g., mixing in a class would work better).
I really don't think we'll ever fix this. There's literally no good way to do it.
Closing: decided above.