#!/usr/bin/env tclsh

package require Itcl

proc logtext { msg } {
    puts "[ clock format [ clock seconds ] -format "%Y-%j-%T" ] - $msg"
}

namespace eval Shared {
    itcl::class Conn {
        constructor { } {
            logtext "  ctor(S) : $this"
        }

        destructor {
            logtext "  dtor(S) : $this"
            logtext "   - THIS SHOULD HAPPEN"
        }
    }
}

namespace eval B {
    itcl::class AltConn {
        inherit ::Shared::Conn

        constructor { } {
            logtext "  ctor(A) : $this"
        }

        destructor {
            logtext "  dtor(A) : $this"
            logtext "   - heritage: [ info heritage ]"
        }
    }

    itcl::class Conn {
        inherit ::Shared::Conn

        constructor { } {
            logtext "  ctor(C) : $this"
        }

        destructor {
            logtext "  dtor(C) : $this"
            logtext "   - heritage: [ info heritage ]"
        }
    }

}

logtext "----- Expected Behavior -----"
logtext "creating A"
set a [ ::B::AltConn \#auto ]
logtext "deleting $a"
itcl::delete object $a

logtext "----- Bad Behavior -----"
logtext "creating C"
set c [ ::B::Conn    \#auto ]
logtext "deleting $c"
itcl::delete object $c

