Open prpr19xx opened 9 months ago
I'll have a think about this. I'm probably not inclined to bake in backward compatibility, but I'll consider an approach that will make it easy for you to do this in your own code without modifying oo.tcl
So can't you simply create your own constructor that behaves as you want rather than using the default constructor?
e.g.
t method constructor {arglist} {
foreach {k v} $arglist {
set $k $v
}
}
Just need to do this for each class you create where you want to use the previous behaviour.
... and that also is easily automated for sugar:
# untested example:
proc makeCompatible {className} {
$className method constructor {arglist} {
foreach {k v} $arglist {
set $k $v
}
}
class t {v1 0 v2 0}
makeCompatible t
You could even sugar it further than that, pretty easily, by rolling that functionality into your own wrapper of the class
command, call it class
, after rename
'ing the original one.
Following on from #248...
Before 5af9d6a, this worked without complaint:
Since then, it generates an error:
t defaultconstructor, v3 is not a class variable
I don't care about v3, I just don't want it to cause any errors (this is a much simplified test-case whereas in reality there are many variables I'm not interested in, but it's huge work to sort in our existing code). As a workaround, I have been manually patching out the "return -code error..." statement that causes it to fail, restoring previous behaviour. But I'd rather not have to patch at all, and it would seem that this is fairly easily fixed by adding something like the following change to allow selectable behaviour:
This maintains the current behaviour, but allows regression to the previous e.g.
There may be a better way, but this works for me.