Tcl Source Code

View Ticket
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.
Ticket UUID: 9dd1bd7a74bc6e9e3e1c0bfd97c42d2df7bacc1
Title: [self] returns empty string in destructor when constructing fails
Type: Bug Version: 1.0.1
Submitter: anonymous Created on: 2015-05-12 16:04:44
Subsystem: 35. TclOO Package Assigned To: dkf
Priority: 8 Severity: Severe
Status: Closed Last Modified: 2015-05-15 14:02:24
Resolution: Fixed Closed By: dkf
    Closed on: 2015-05-15 14:02:24
Invoking [self] in the destructor returns an empty string if an error was raised in the constructor, except if [self] had been invoked in the constructor prior to the error.  Please, see following recipe to reproduce:

# TclOO bug.  [self] returns no value on the destructor if:
# - There is an error while constructing the object.
# - [self] is not invoked prior to the error.
::oo::class create noself {
    constructor {args} {
	error "Some error in NOSELF constructor.";
    destructor {
	puts "I have no self='[self]'.";

::oo::class create yesself {
    constructor {args} {
	error "Some error in the YESSELF constructor after invoking \[self\].";
    destructor {
	puts "I do have self='[self]'.";

catch {noself new};
catch {yesself new};

The script outputs the following:

I have no self=''.
I do have self='::oo::Obj24'.
User Comments: dkf added on 2015-05-15 14:02:24:
Should be fixed in Tcl 8.6 and next release of TclOO package.

dkf added on 2015-05-15 13:26:07:

Good catch; it's a race between the construction of the name and the deletion, with some traces in the mix too to make it all complicated.