Skip to content
Tcl Source Code View Ticket
Login

View Ticket

tailcall from constructor doesn't quite work.

Closed / Fixed2414858fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2008-12-10 21:09:31
Consider:

proc bar {} {}
oo::class create foo {
    constructor {
        tailcall bar
    }
}
set x [foo new]

$x does not get the name of the newly-created object.
dgpplain2008-12-11 04:54:02
dkfand I know what the problem is: it's running the post-constructor code before running the tailcalled stuff
dkfplain2008-12-11 08:33:21
Just because I know what the problem is doesn't mean (in this case) that I know how to fix it. The issue is that the constructors need to run code after all the constructors have run (to do things like ensure that the result is the name of the object).

Arguably it's wrong to tailcall in constructors in the first place. But in any case I need advice. Assigning this to someone who knows more about the tailcall stuff.
dkf Ticket [2414858fff]: 1 change [History diff]2008-12-11 08:33:22
msoferplain2009-03-22 06:46:35
The solution might just be: let the constructor code run as a command through TEOV, or else (hacky) manually add a 
   Tcl_NRAddCallback(NRCommand,NULL, ...);
   iPtr->numLevels++;
at the spot where the tailcalls should run (ie, after pushing the post-constructor callbacks, before pushing the actual constructor callbacks). NRCommand serves as the marker for the tailcall spot.

This might make the tailcalls run properly - if there is an effect of numLevels on tip 280 things, I don't know
msofer Ticket [2414858fff]: 1 change [History diff]2009-05-01 08:24:16
msofer Ticket [2414858fff]: 1 change [History diff]2009-05-08 09:04:41
dkfplain2009-05-08 15:39:55
Constructor can't run through TEOV; it's not a command (different signature, etc).
dkfplain2009-05-08 15:50:46
allow_comments - 1

Fixed. Hack is kept in tclBasic.c with an internal function that tclOO.c calls at the right point. Test oo-2.6 checks that this issue is handled correctly.
Log in (anonymous is fine) to add a comment.