Index: TODO =================================================================== diff -u -red0f5cba982af963b62c36d8c8c75e89c81adf3e -r4b78042d08af7f3200d51f4033d5164c949f332d --- TODO (.../TODO) (revision ed0f5cba982af963b62c36d8c8c75e89c81adf3e) +++ TODO (.../TODO) (revision 4b78042d08af7f3200d51f4033d5164c949f332d) @@ -5843,21 +5843,21 @@ - Added Rosetta example: https://rosettacode.org/wiki/Add_a_variable_to_a_class_instance_at_runtime -======================================================================== -TODO: - - Improve error message with {*} operator, not 'unknown'. Object new { :object method foo {a b c args} { puts --[current method]} - {*}[list :foo 1 2 3 4 5 6]; # Should be equivalendt to ':foo 1 2 3 4 5 6', but isn't - : {*}[list foo 1 2 3 4 5 6]; # Should be equivalent to ':foo 1 2 3 4 5 6', but isn't + {*}[list :foo 1 2 3 4 5 6]; + : {*}[list foo 1 2 3 4 5 6]; catch {:{*}[list foo 1 2 3 4 5 6]} msg; puts msg=$msg } proc =foo {a b c args} { puts foo } catch {={*}[list foo 1 2 3 4 5 6]} msg; puts msg=$msg +======================================================================== +TODO: + - Under core-8-5-branch, make test --enable-development yields an assertion failure: ./tests/parameters.test Index: generic/nsf.c =================================================================== diff -u -re20e1c1aa5e3b8f1020a455605d6f971ab622f5b -r4b78042d08af7f3200d51f4033d5164c949f332d --- generic/nsf.c (.../nsf.c) (revision e20e1c1aa5e3b8f1020a455605d6f971ab622f5b) +++ generic/nsf.c (.../nsf.c) (revision 4b78042d08af7f3200d51f4033d5164c949f332d) @@ -14207,23 +14207,24 @@ } else { /* no unknown called, this is the built-in unknown handler */ Tcl_Obj *tailMethodObj = NULL; - if (objc > 1 && ((*methodName) == '-' || (unknownObj && objv[0] == unknownObj))) { int length; - if (Tcl_ListObjLength(interp, objv[1], &length) == TCL_OK && length > 0) { - Tcl_ListObjIndex(interp, objv[1], length - 1, &tailMethodObj); + tailMethodObj = objv[1]; + if (Tcl_ListObjLength(interp, objv[1], &length) == TCL_OK) { + if (length > 1) { + Tcl_ListObjIndex(interp, objv[1], length - 1, &tailMethodObj); + } } } - result = NsfPrintError(interp, "%s: unable to dispatch method '%s'", ObjectName_(object), (tailMethodObj != NULL) ? MethodName(tailMethodObj) : methodName); } - + /* * Reset interp state, unknown has been fired. */ rst->unknown = 0; - + return result; } Index: tests/methods.test =================================================================== diff -u -r3c1482d9e1f80f0216250f5debade5d8edb1b17e -r4b78042d08af7f3200d51f4033d5164c949f332d --- tests/methods.test (.../methods.test) (revision 3c1482d9e1f80f0216250f5debade5d8edb1b17e) +++ tests/methods.test (.../methods.test) (revision 4b78042d08af7f3200d51f4033d5164c949f332d) @@ -230,6 +230,60 @@ ? {o eval :foo} "::o: unable to dispatch method 'foo'" } +nx::test case colon-unknown { + set o [nx::Object new { + :object method foo {a b c args} { return [current method]-ok } + + ## Expansion to valid method calls (messages) + :object method expand-non-empty-list-1 {} { + {*}[list :foo 1 2 3 4 5 6]; + } + :object method expand-non-empty-list-2 {} { + : {*}[list foo 1 2 3 4 5 6]; + } + :object method expand-self-call-1 {} { + {*}[list :]; + } + :object method expand-self-call-2 {} { + : {*}[list]; + } + + ## (Non-)expansion & unknown + :object method expand-unknown-1 {} { + :{*}[list foo 1 2 3 4 5 6]; # no expansion, yielding invalid list as method name + } + :object method expand-unknown-2 {} { + :{*}[list]; # no expansion, yielding invalid list as method name + } + :object method expand-unknown-3 {} { + :{*}; # no expansion, yielding invalid list as method name + } + :object method expand-unknown-4 {} { + :{*}{}; # no expansion, yielding invalid list as method name + } + :object method expand-unknown-5 {} { + :{\}}; # yet another invalid list (no expansion op) + } + }] + + ? [list $o expand-non-empty-list-1] "foo-ok" + ? [list $o expand-non-empty-list-2] "foo-ok" + ? [list $o expand-self-call-1] $o + ? [list $o expand-self-call-2] $o + + # + # Keep unknown messages compatible with Tcl's 'invalid command' + # messages in the cases below, e.g.: + # + # proc =foo {args} {;}; ={*}[list foo 1 2 3 4 5 6] + # + ? [list $o expand-unknown-1] "$o: unable to dispatch method '{*}foo 1 2 3 4 5 6'" + ? [list $o expand-unknown-2] "$o: unable to dispatch method '{*}'" + ? [list $o expand-unknown-3] "$o: unable to dispatch method '{*}'" + ? [list $o expand-unknown-4] "$o: unable to dispatch method '{*}{}'" + ? [list $o expand-unknown-5] "$o: unable to dispatch method '{\}}'" +} + nx::test case mixinguards { # define a Class C and mixin class M nx::Class create C