Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Incompatible change in behavior of -private option to info class methods command

Closed / Fixed36e5517a6850c19300547700954912678fd46703Created 3 years agoUpdated 3 years ago
Descriptionmarkdown2024-05-03 06:50:25

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.

apnadkarni Ticket [36e5517a68]: 3 changes [History diff]2024-05-03 07:09:27
oehharwiki2024-05-03 07:18:43

Great catch! I hope, Donal will comment. Some tests here would be great too...

Thanks, Harald

dkfmarkdown2024-05-15 18:42:03

I don't recall specifically changing this.

dkfmarkdown2024-05-15 18:49:47

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.

oehharwiki2024-05-16 06:52:20

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

dkfmarkdown2024-05-16 07:52:33

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 also InfoObjectMethodsCmd) in tclOOInfo.c,
  • TclOOGetSortedMethodList and TclOOGetSortedClassMethodList in tclOOCall.c, and
  • the testing of info class methods (and probably info object methods) in oo.test (around oo-17.* would have been the right place)

I'm particularly irritated that there isn't a test of this case.

dkf Ticket [36e5517a68]: 4 changes [History diff]2024-05-16 07:58:05
dkfmarkdown2024-05-16 08:45:40

tclOOCall.c is uninvolved; that's only ever used when the -all option is passed.

dkfmarkdown2024-05-16 08:53:33

Will be fixed by bug-36e5517a6850.

dkf Closed ticket [36e5517a68]. [History diff]2024-05-16 08:53:49
Log in (anonymous is fine) to add a comment.