Index: TODO =================================================================== diff -u -rb37bf2deab94b6294509fa79bb7b922d6e8a5635 -rc7686b76eff01e25abf042d5b4fa2dfa998b22f1 --- TODO (.../TODO) (revision b37bf2deab94b6294509fa79bb7b922d6e8a5635) +++ TODO (.../TODO) (revision c7686b76eff01e25abf042d5b4fa2dfa998b22f1) @@ -3533,7 +3533,19 @@ - added configure option: enable-assertions (default on) +- nsf.c: + * allowed to call ":" like "my" or "self" + + Object create o + o public method bar2 {} {return bar2-[: foo]} + o public method bar5 {} {return [self]::bar5} + o public method bar6 {} {return [:]::bar6} + + * extended regression test + + TODO: + - NSF_WITH_OS_RESOLVER - private: * document private in tutorial - add "property" and "attribute" and "info property" and "info slot ..." to migration guide Index: generic/nsf.c =================================================================== diff -u -rb37bf2deab94b6294509fa79bb7b922d6e8a5635 -rc7686b76eff01e25abf042d5b4fa2dfa998b22f1 --- generic/nsf.c (.../nsf.c) (revision b37bf2deab94b6294509fa79bb7b922d6e8a5635) +++ generic/nsf.c (.../nsf.c) (revision c7686b76eff01e25abf042d5b4fa2dfa998b22f1) @@ -3605,6 +3605,9 @@ } } + /*fprintf(stderr, "InterpColonCmdResolver cmdName %s flags %.6x, frame flags %.6x\n", + cmdName, flags, Tcl_CallFrame_isProcCallFrame(varFramePtr));*/ + #if defined(CMD_RESOLVER_TRACE) fprintf(stderr, "InterpColonCmdResolver cmdName %s flags %.6x, frame flags %.6x\n", cmdName, flags, Tcl_CallFrame_isProcCallFrame(varFramePtr)); @@ -3652,8 +3655,8 @@ cmd = osPtr->rootClass->object.id; cmdTablePtr = Tcl_Namespace_cmdTablePtr(((Command *)cmd)->nsPtr); entryPtr = Tcl_CreateHashEntry(cmdTablePtr, cmdName, NULL); - /* fprintf(stderr, "InterpColonCmdResolver OS specific resolver tried to lookup %s for os %s in ns %s\n", - cmdName, ClassName(osPtr->rootClass), ((Command *)cmd)->nsPtr->fullName);*/ + /*fprintf(stderr, "InterpColonCmdResolver OS specific resolver tried to lookup %s for os %s in ns %s\n", + cmdName, ClassName(osPtr->rootClass), ((Command *)cmd)->nsPtr->fullName);*/ if (entryPtr) { /*fprintf(stderr, "InterpColonCmdResolver OS specific resolver found %s::%s\n", ((Command *)cmd)->nsPtr->fullName, cmdName);*/ @@ -17499,11 +17502,21 @@ */ static int NsfColonCmd(Tcl_Interp *interp, int nobjc, Tcl_Obj *CONST nobjv[]) { + CONST char *methodName = ObjStr(nobjv[0]); NsfObject *self = GetSelfObj(interp); if (unlikely(self == NULL)) { - return NsfNoCurrentObjectError(interp, ObjStr(nobjv[0])); + return NsfNoCurrentObjectError(interp, methodName); } - /* fprintf(stderr, "Colon dispatch %s.%s\n", ObjectName(self), ObjStr(nobjv[0]));*/ + /*fprintf(stderr, "Colon dispatch %s.%s (%d)\n", + ObjectName(self), ObjStr(nobjv[0]), nobjc);*/ + + if (*methodName == ':' && *(methodName + 1) == '\0') { + if (nobjc > 1) { + return ObjectDispatch(self, interp, nobjc, nobjv, 0); + } else { + return DispatchDefaultMethod(interp, (NsfObject *)self, nobjv[0], 0); + } + } return ObjectDispatch(self, interp, nobjc, nobjv, NSF_CM_NO_SHIFT); } Index: tests/object-system.test =================================================================== diff -u -r8046b1da6bc0689f73d4dbdc3f8d1e03fd23acaf -rc7686b76eff01e25abf042d5b4fa2dfa998b22f1 --- tests/object-system.test (.../object-system.test) (revision 8046b1da6bc0689f73d4dbdc3f8d1e03fd23acaf) +++ tests/object-system.test (.../object-system.test) (revision c7686b76eff01e25abf042d5b4fa2dfa998b22f1) @@ -110,6 +110,29 @@ ? {::nsf::is metaclass c1} 0 ? {c1 info class} ::nx::Object + +# +# tests for dispatching methods +# +Object create o +o public method foo {} {return foo} +o public method bar1 {} {return bar1-[:foo]} +o public method bar2 {} {return bar2-[: foo]} +o public method bar3 {} {return bar3-[my foo]} +o public method bar4 {} {return bar4-[[self] foo]} +o public method bar5 {} {return [self]::bar5} +o public method bar6 {} {return [:]::bar6} + +# dispatch without colon names +? {o foo} foo "simple method dispatch" +? {o bar1} bar1-foo "colon-methodname dispatch" +? {o bar2} bar2-foo "colon cmd dispatch" +? {o bar3} bar3-foo "my dispatch" +? {o bar4} bar4-foo "self dispatch" +? {o bar5} ::o::bar5 "self cmd" +? {o bar6} ::o::bar6 "colon cmd" +o destroy + # basic attributes tests Class create C {