#3696 autoloading causes (itcl) 'class already exists' error

obsolete: 8.4.14
Don Porter

There is a 'bug' in the itcl implementation of auto_mkindex_parser::command, that causes an error message saying:
class "::A" already exists
if it is combined with a simple error in the itcl class and autoloading.

I realize this is not completely a tcl core problem, however the autoload package already appears to try to 'defend' against errors in external parser commands, and if this case could also be caught, it could return a much better error message.

Example in the attachment, in short: itcl allows you to declare a proc but implement it later (C++ style separation of header and implementation). itcl has implemented the parsing for autoload by adding the proc to the autoload list when the declaration is seen (probably because you can also implement the proc inline with the declaration, again matching C++ style.)

Now, if you declare but not implement a proc, it is listed in the tclindex file, but after sourcing the file, the command is still not defined. However, the current checks against this all pass.
Then, the command is started, causing a recursive call into the autoload code, which sources the file again, which results in the error.

(I have tried to reproduce this without itcl, but haven't been able to. I don't fully understand how itcl creates it's class procedures as tcl procs and namespaces, and how this succeeds in bypassing the existing checks.)

Note: tested using itcl 3.3, everything was installed by activestate's 8.4.14 tcl installer, on windows xp sp2.


  • legolas_a20

    Example itcl class and file attempting to autoload it.