Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2025-02-20
13:04 • Closed ticket [6d4319309e]: Parent-Class destructor not invoked with same class-... artifact: 0bc0d86c30 user: sebres
2025-02-13
22:06 • Ticket [6d4319309e]: 3 changes artifact: 406af42c23 user: sebres
2025-02-12
22:40 • Add attachment namespace-class-destructor.tcl to ticket [6d4319309e9061... artifact: 5bd5390c67 user: anonymous
22:37 • New ticket [6d4319309e] Parent-Class destructor not invoked with same class-name... artifact: 6a170d507b user: anonymous

Parent-Class destructor not invoked with same class-name in different namespace

Closed / Fixed6d4319309e906144741e49f8790647b2dffb452aCreated 2 years agoUpdated 2 years ago
Descriptionplain2025-02-12 22:37:45
When a class is defined in a namespace and it inherits from a class with the same name from a different namespace and an object from the child class is destroyed, the destructor from the parent class does not get invoked.
sebresmarkdown2025-02-13 22:06:57

It seems to be solely Itcl (v.4) issue (thus the correct place for the ticket would be itcl/ticket).

Below enclosed the PoC for tclOO (basis of Itcl since Itcl4), that works as expected:

PoC ...

namespace eval ::A {}; namespace eval ::B {}
oo::class create ::A::testCls {
  superclass oo::class
  destructor { puts "bye from ::A::testCls" }
}

oo::class create ::C::testOtherCls {
  superclass ::A::testCls
  destructor { puts "bye from ::C::testOtherCls"; next }
}
oo::class create ::C::testCls {
  superclass ::A::testCls
  destructor { puts "bye from ::C::testCls"; next }
}

set o [::C::testOtherCls new]
$o destroy
puts =================
set o [::C::testCls new]
$o destroy

## results to:

bye from ::C::testOtherCls
bye from ::A::testCls
=================
bye from ::C::testCls
bye from ::A::testCls

Although in tclOO inherited destructor need to be invoked explicitly (using next).

I guess, Itcl stores somewhere (hash table?) the chain of destructors by simple name (instead of its reference or fully-qualified name).

sebresmarkdown2025-02-20 13:04:29

Yes, my suspicion about simple name in hash table has been confirmed...
Fixed in [itcl/883c2c383fee7603], related ticket [itcl/987067386fa2edae].

Log in (anonymous is fine) to add a comment.