Skip to content
Tcl Source Code View Ticket
Login

View Ticket

oo::class appears to confiscate the 'create' method on all its descendants.

Closed / Invalid794298036fda15d18e9ee7251bb948dabe8fd498Created 9 years agoUpdated 9 years ago
Descriptionplain2018-06-02 07:14:33
oo::class 'create' is a method.

If I derive an instance of oo::class which contains a method 'create', I cannot call its create method.

The following snipped should error, but does not, because Class's create method is intercepted by oo::class.  This is a bug.  One should reasonably expect to be able to override methods, and this appears to be true for other methods which one might define (in the example below) on Class.

Colin.

Demonstration:  I would expect Class 'create' to be called, but it is not.

oo::class create Class {
    method create {args} {
	error "Should Error, but doesn't - this is a bug, it means no oo::class instance can override create method"
    }
}
Class create Instance

oo::class create MClass {
    superclass ::oo::class
    method create {args} {
	error "Should Error, but doesn't - this is a bug, it means no oo::class instance can override create method"
    }
}
MClass create MInstance
dgpplain2018-06-02 11:18:16
This looks like a confusion between the instance relationship and the
inheritance relationship.

To override [Class create], use [oo::objdefine]:

% oo::class create Class {
    method create {args} {
	error "Should Error, but doesn't - this is a bug, it means no oo::class instance can override create method"
    }
}
::Class
% Class create Instance
::Instance


% oo::objdefine Class method create args {error demo}
% Class create Demo
demo
Log in (anonymous is fine) to add a comment.