Tcl Source Code

View Ticket
Login
Ticket UUID: 9d0cfbc51e3b6281aae4447c3603591dc0ec35d9
Title: method [create] is handled very differently from other methods
Type: Bug Version: tcl8.6.1
Submitter: cmcc Created on: 2014-01-27 00:45:04
Subsystem: 35. TclOO Package Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2014-01-27 12:01:47
Resolution: Invalid Closed By: dkf
    Closed on: 2014-01-27 12:01:47
Description:
From the following:

oo::class create creator {
    method moop {args} {
	puts stderr "moop"
    }
    method create {args} {
	puts stderr "create"
    }
    constructor {args} {
	puts stderr "constructed"
    }
}

creator create fred
fred moop

I get the output:

constructed
moop

Where I would have expected to see 'create' ... this represents a pretty significant change to the relationship between oo::class and the rest over earlier tcloo versions, and also suggests that "create" has become something of a reserved word within tcloo.

Is there some documentation for this behaviour?

Colin
User Comments: dkf added on 2014-01-27 12:01:47: (text/html)
Everything looks fine to me, and I've not done anything odd here for ages.
<pre>
% oo::class create creator {
    method moop {args} {
	puts stderr "moop"
    }
    method create {args} {
	puts stderr "create"
    }
    constructor {args} {
	puts stderr "constructed"
    }
}
::creator
% creator ?
unknown method "?": must be create, destroy or new
% creator create fred
constructed
::fred
% fred ?
unknown method "?": must be create, destroy or moop
</pre>
However, it should be noted that the <tt>create</tt> that you normally see is the one provided by the <i>class</i> object, not the instance object. It's actually a normal method that is implemented in C and defined on the <tt>oo::class</tt> class.
<pre>
% info class methods oo::class
create new
% info class methods oo::class -all
create destroy new
</pre>
(The <tt>-all</tt> means use the superclass method implementations as well, so it picks it up from the <tt>oo::object</tt> class.)
<p>
Metaclasses are funky stuff.