Index: TODO =================================================================== diff -u -r17ad6747e40c1724810371f92f0108b12c1d5284 -r9f32dd2c379759ca82cf9b49dcc9c62af01f5cc8 --- TODO (.../TODO) (revision 17ad6747e40c1724810371f92f0108b12c1d5284) +++ TODO (.../TODO) (revision 9f32dd2c379759ca82cf9b49dcc9c62af01f5cc8) @@ -3915,14 +3915,15 @@ - extended regression test - don't allow object creation to overwrite non-object cmds (e.g. procs) +- don't allow method to overwrite child object +- extended regression test ======================================================================== TODO: - document new setable object properties perobjectdispatch and keepcallerself - pertaining perobjectdispatch and keepcallerself in serializer -- should we allow objects to overwrite procs/methods and vice versa? - behavior on keepcallerself on ordinary dispatches with implicit/explicit receiver (currently the flag is ignored, the code just commented out) Index: doc/next-migration.html =================================================================== diff -u -rb343f7d7927f4adb06ecdbb32aa4e14100d16a89 -r9f32dd2c379759ca82cf9b49dcc9c62af01f5cc8 --- doc/next-migration.html (.../next-migration.html) (revision b343f7d7927f4adb06ecdbb32aa4e14100d16a89) +++ doc/next-migration.html (.../next-migration.html) (revision 9f32dd2c379759ca82cf9b49dcc9c62af01f5cc8) @@ -6856,7 +6856,15 @@ ::nsf::relation f1 class ::nx::Object
-

3.2.4. Info heritage

+

3.2.4. Overwriting procs/methods with objects and vice versa

+

NSF is now more conservative on object/method creation. In contrary to +XOTcl 1 NSF does not allow to redefined a pre-existing command +(e.g. "set") with an object and vice versa. Like in XOTcl 1, +preexisting objects and classes con be redefined (necessary for +reloading objects/classes in an running interpreter).

+
+
+

3.2.5. Info heritage

info heritage returns in XOTcl 1 the transitive superclass hierarchy, which is equivalent with info superclass -closure and therefore not necessary. In XOTcl 2 (and NX), info heritage includes @@ -6907,7 +6915,7 @@

Index: doc/next-migration.txt =================================================================== diff -u -r2b1c0832de70a62dfd45b4935eceedaf02777e7e -r9f32dd2c379759ca82cf9b49dcc9c62af01f5cc8 --- doc/next-migration.txt (.../next-migration.txt) (revision 2b1c0832de70a62dfd45b4935eceedaf02777e7e) +++ doc/next-migration.txt (.../next-migration.txt) (revision 9f32dd2c379759ca82cf9b49dcc9c62af01f5cc8) @@ -2939,6 +2939,14 @@ ::nsf::relation f1 class ::nx::Object ---------------- +==== Overwriting procs/methods with objects and vice versa + +NSF is now more conservative on object/method creation. In contrary to +XOTcl 1 NSF does not allow to redefined a pre-existing command +(e.g. "set") with an object and vice versa. Like in XOTcl 1, +preexisting objects and classes con be redefined (necessary for +reloading objects/classes in an running interpreter). + ==== Info heritage +info heritage+ returns in XOTcl 1 the transitive superclass hierarchy, which is equivalent with +info superclass -closure+ and Index: generic/nsf.c =================================================================== diff -u -r17ad6747e40c1724810371f92f0108b12c1d5284 -r9f32dd2c379759ca82cf9b49dcc9c62af01f5cc8 --- generic/nsf.c (.../nsf.c) (revision 17ad6747e40c1724810371f92f0108b12c1d5284) +++ generic/nsf.c (.../nsf.c) (revision 9f32dd2c379759ca82cf9b49dcc9c62af01f5cc8) @@ -4844,7 +4844,20 @@ assert(nsPtr); cmd = FindMethod(nsPtr, methodName); - ok = cmd ? (Tcl_Command_flags(cmd) & NSF_CMD_REDEFINE_PROTECTED_METHOD) == 0 : 1; + if (cmd) { + if ( NsfGetObjectFromCmdPtr(cmd) != NULL) { + /* + * Don't allow overwriting of an object with an method. + */ + return NsfPrintError(interp, + "cannot overwrite child object with method %s; delete/rename it before overwriting", + methodName); + } + ok = (Tcl_Command_flags(cmd) & NSF_CMD_REDEFINE_PROTECTED_METHOD) == 0; + } else { + ok = 1; + } + if (ok) { result = TCL_OK; } else { @@ -22141,8 +22154,9 @@ } /* - * Check whether we have to call recreate (i.e. when the - * object exists already). + * Check whether we have to call recreate (i.e. when the object exists + * already). First check, if was have such a command, then check, if the + * command is an object. */ { Tcl_Command cmd = NSFindCommand(interp, nameString); Index: tests/object-system.test =================================================================== diff -u -r17ad6747e40c1724810371f92f0108b12c1d5284 -r9f32dd2c379759ca82cf9b49dcc9c62af01f5cc8 --- tests/object-system.test (.../object-system.test) (revision 17ad6747e40c1724810371f92f0108b12c1d5284) +++ tests/object-system.test (.../object-system.test) (revision 9f32dd2c379759ca82cf9b49dcc9c62af01f5cc8) @@ -357,8 +357,26 @@ # ? {catch {nx::Object create [self]::bar}} 1 } +nx::Object create foo { + nx::Object create [self]::bar + # + # Don't allow child-object to be overwritten by object specific cmd + # + ? {catch {:forward bar somethingelse}} 1 + ? {nsf::object::exists [self]::bar} 1 + # + # Don't allow child-object to be overwritten by object specific + # scripted method + # + ? {catch {:method bar {} {;}}} 1 + ? {nsf::object::exists [self]::bar} 1 +} +foo destroy + + + # # Test instances of diamond class structure. #