From fa7659336ca6c01fbed7cf8497b29e9191b0cb42 Mon Sep 17 00:00:00 2001 From: pooryorick Date: Sat, 27 Jan 2018 18:17:09 +0000 Subject: Remove restriction on defining the class of a TclOO object not explicitly instantiated from ::oo::class. --- generic/tclOODefineCmds.c | 15 --------------- tests/oo.test | 4 ++-- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/generic/tclOODefineCmds.c b/generic/tclOODefineCmds.c index c08b350..7c2a641 100644 --- a/generic/tclOODefineCmds.c +++ b/generic/tclOODefineCmds.c @@ -1143,7 +1143,6 @@ TclOODefineClassObjCmd( { Object *oPtr; Class *clsPtr; - Foundation *fPtr = TclOOGetFoundation(interp); /* * Parse the context to get the object to operate on. @@ -1180,20 +1179,6 @@ TclOODefineClassObjCmd( return TCL_ERROR; } - /* - * Apply semantic checks. In particular, classes and non-classes are not - * interchangable (too complicated to do the conversion!) so we must - * produce an error if any attempt is made to swap from one to the other. - */ - - if ((oPtr->classPtr==NULL) == TclOOIsReachable(fPtr->classCls, clsPtr)) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "may not change a %sclass object into a %sclass object", - (oPtr->classPtr==NULL ? "non-" : ""), - (oPtr->classPtr==NULL ? "" : "non-"))); - Tcl_SetErrorCode(interp, "TCL", "OO", "TRANSMUTATION", NULL); - return TCL_ERROR; - } /* * Set the object's class. diff --git a/tests/oo.test b/tests/oo.test index 3be5f79..4f9490b 100644 --- a/tests/oo.test +++ b/tests/oo.test @@ -1707,13 +1707,13 @@ test oo-13.2 {OO: changing an object's class} -body { oo::objdefine foo class oo::class } -cleanup { foo destroy -} -returnCodes 1 -result {may not change a non-class object into a class object} +} -result {} test oo-13.3 {OO: changing an object's class} -body { oo::class create foo oo::objdefine foo class oo::object } -cleanup { foo destroy -} -returnCodes 1 -result {may not change a class object into a non-class object} +} -result {} test oo-13.4 {OO: changing an object's class} -body { oo::class create foo { method m {} { -- cgit v0.12