Incompatible change in behavior of -private option to info class methods command
In 8.6
% oo::class create C {method Private {} {}; method public {} {}}
::C
% info class methods ::C
public
% info class methods ::C -private
public Private
The above works as documented as the -private option will return private methods in addition to public methods as stated in the manpage If the -private flag is given, the list of methods will also include the private... (note the "also").
In Tcl 9, this is not the case
% oo::class create C {method Private {} {}; method public {} {}}
::C
% info class methods ::C
public
% info class methods ::C -private
Private
Note the -private option now returns only private methods. However, the documentation still seems to match 8.6 behavior: If the -private flag is given, and the -scope flag is not given, the list of methods will also include the non-exported methods of the class
I'm not sure if the Tcl 9 implementation needs to be fixed or the documentation. If the latter, an Tcl 8 incompatibility note would be desirable.
Great catch! I hope, Donal will comment. Some tests here would be great too...
Thanks, Harald
I don't recall specifically changing this.
The only likely looking changes would be from 9294775086c983a3 (TIP #500) and the result of that particular call is supposed to remain identical. (info class methods $cls -scope private would be different...)
I really thought I had test cases for all this.
Donal, thank you looking into this.
So, the answer is, that this change was not intentional and "-private" should list public and private methods.
That is an important statement. Perhaps other Wizards may find the cause...
Thank you for all, Harald
It should list exactly the methods listed in 8.6. However, the set of possible methods is expanded:
oo::class create C {
method foo {} {}
method Bar {} {}
private method gorp {} {}
}
puts [info class methods C -private]
This should list foo and Bar (in some order) but not gorp; that should only be present if -scope private is passed (and then that only fetches gorp; -scope doesn't work the same way).
The problem likely lies between:
InfoClassMethodsCmd(and probably alsoInfoObjectMethodsCmd) in tclOOInfo.c,TclOOGetSortedMethodListandTclOOGetSortedClassMethodListin tclOOCall.c, and- the testing of
info class methods(and probablyinfo object methods) in oo.test (aroundoo-17.*would have been the right place)
I'm particularly irritated that there isn't a test of this case.
tclOOCall.c is uninvolved; that's only ever used when the -all option is passed.
Will be fixed by bug-36e5517a6850.