Index: TODO =================================================================== diff -u -r511fca2017ee0cabbfef93bfb482cd165def8190 -r96716c484bb18d390fef1eecdca764b56121dc4d --- TODO (.../TODO) (revision 511fca2017ee0cabbfef93bfb482cd165def8190) +++ TODO (.../TODO) (revision 96716c484bb18d390fef1eecdca764b56121dc4d) @@ -1889,6 +1889,14 @@ - extended regression test with testcases for creation of parent objects via method "__unknown" +- disallow object parameter of type "switch" to avoid possible + confusion between (a) providing a value for the o.p., (b) calling + it as a setter, and (c) calling it as a getter. For providing a + value, no arg is used for switch. For calling a setter, it is + necessary to provide a value even for a switch. +- disallow type "switch" in setter definiton (use boolean instead) +- disallow type "switch" for positional arguments (use boolean instead) +- extended regression test TODO: Index: generic/nsf.c =================================================================== diff -u -rbf14514386be7b9b2b97e3790ea9ec78c8e11b22 -r96716c484bb18d390fef1eecdca764b56121dc4d --- generic/nsf.c (.../nsf.c) (revision bf14514386be7b9b2b97e3790ea9ec78c8e11b22) +++ generic/nsf.c (.../nsf.c) (revision 96716c484bb18d390fef1eecdca764b56121dc4d) @@ -474,7 +474,7 @@ * NsfObject Reference Accounting */ #if defined(NSFOBJ_TRACE) -# define NsfObjectRefCountIncr(obj) \ +# define NsfObjectRefCountIncr(obj) \ (obj)->refCount++; \ fprintf(stderr, "RefCountIncr %p count=%d %s\n", obj, obj->refCount, obj->cmdName?ObjStr(obj->cmdName):"no name"); \ MEM_COUNT_ALLOC("NsfObject RefCount", obj) @@ -8098,6 +8098,13 @@ paramPtr->converterArg = Tcl_NewStringObj(option+4, length-4); INCR_REF_COUNT(paramPtr->converterArg); } else if (strncmp(option, "switch", 6) == 0) { + fprintf(stderr, "switch name %s\n", paramPtr->name); + if (*paramPtr->name != '-') { + return NsfVarErrMsg(interp, + "invalid parameter type \"switch\" for argument ", paramPtr->name, + "; type \"switch\" only allowed for non-positional arguments", + (char *) NULL); + } result = ParamOptionSetConverter(interp, paramPtr, "switch", ConvertToSwitch); paramPtr->flags |= NSF_ARG_SWITCH; paramPtr->nrArgs = 0; Index: generic/nsfInt.h =================================================================== diff -u -r511fca2017ee0cabbfef93bfb482cd165def8190 -r96716c484bb18d390fef1eecdca764b56121dc4d --- generic/nsfInt.h (.../nsfInt.h) (revision 511fca2017ee0cabbfef93bfb482cd165def8190) +++ generic/nsfInt.h (.../nsfInt.h) (revision 96716c484bb18d390fef1eecdca764b56121dc4d) @@ -373,8 +373,8 @@ /* Disallowed parameter options */ #define NSF_DISALLOWED_ARG_METHOD_PARAMETER (NSF_ARG_METHOD|NSF_ARG_INITCMD|NSF_ARG_RELATION) -#define NSF_DISALLOWED_ARG_SETTER (NSF_ARG_SUBST_DEFAULT|NSF_DISALLOWED_ARG_METHOD_PARAMETER) -#define NSF_DISALLOWED_ARG_OBJECT_PARAMETER 0 +#define NSF_DISALLOWED_ARG_SETTER (NSF_ARG_SWITCH|NSF_ARG_SUBST_DEFAULT|NSF_DISALLOWED_ARG_METHOD_PARAMETER) +#define NSF_DISALLOWED_ARG_OBJECT_PARAMETER (NSF_ARG_SWITCH) #define NSF_DISALLOWED_ARG_VALUECHECK (NSF_ARG_SUBST_DEFAULT|NSF_ARG_METHOD|NSF_ARG_INITCMD|NSF_ARG_RELATION|NSF_ARG_SWITCH|NSF_ARG_CURRENTLY_UNKNOWN) Index: library/nx/nx.tcl =================================================================== diff -u -r5fa3584b0f682d4103c39af82357713871f1de0c -r96716c484bb18d390fef1eecdca764b56121dc4d --- library/nx/nx.tcl (.../nx.tcl) (revision 5fa3584b0f682d4103c39af82357713871f1de0c) +++ library/nx/nx.tcl (.../nx.tcl) (revision 96716c484bb18d390fef1eecdca764b56121dc4d) @@ -614,7 +614,9 @@ } } } + if {[info exists type]} { + if {$type eq "switch"} {error "switch is not allowed as type for object parameter $name"} lappend opts -type $type } @@ -801,6 +803,7 @@ set objopts [list] set methodopts [list] set type "" + if {[info exists :required] && ${:required}} { lappend objopts required lappend methodopts required Index: tests/parameters.test =================================================================== diff -u -r277704be44e8205d6aa0507c840e44223039f841 -r96716c484bb18d390fef1eecdca764b56121dc4d --- tests/parameters.test (.../parameters.test) (revision 277704be44e8205d6aa0507c840e44223039f841) +++ tests/parameters.test (.../parameters.test) (revision 96716c484bb18d390fef1eecdca764b56121dc4d) @@ -195,7 +195,7 @@ # relation NO YES NO NO YES NO NO YES # stringtype YES YES NO NO NO YES YES YES # -# switch NO NO NO NO NO NO YES YES +# switch NO NO NO NO NO NO YES NO # integer YES YES NO NO NO YES YES YES # boolean YES YES NO NO NO YES YES YES # object YES YES NO YES NO YES YES YES @@ -477,19 +477,21 @@ {literal "\\[current\\]"} {c "[:info class]"} {d "literal $d"} - {switch:switch} } + + ? {Bar attribute ss:switch} "switch is not allowed as type for object parameter ss" + Bar create bar1 #puts stderr [bar1 objectparameter] - ? {subst {[bar1 s]-[bar1 literal]-[bar1 c]-[bar1 d]-[bar1 switch]}} \ - {::bar1-[current]-::Bar-literal $d-0} \ - "substdefault and switch in object parameter 1" + ? {subst {[bar1 s]-[bar1 literal]-[bar1 c]-[bar1 d]}} \ + {::bar1-[current]-::Bar-literal $d} \ + "substdefault in object parameter 1" - Bar create bar2 -switch - ? {subst {[bar2 s]-[bar2 literal]-[bar2 c]-[bar2 d]-[bar2 switch]}} \ - {::bar2-[current]-::Bar-literal $d-1} \ - "substdefault and switch in object parameter 2" + Bar create bar2 + ? {subst {[bar2 s]-[bar2 literal]-[bar2 c]-[bar2 d]}} \ + {::bar2-[current]-::Bar-literal $d} \ + "substdefault in object parameter 2" # Observations: # 1) syntax for "-attributes" and method parameter is quite different. @@ -506,7 +508,7 @@ # 2) substdefault for '$' in -attributes defaults does not make much sense. # deactivated for now; otherwise we would need "\\" - D method bar { + D public method bar { {-s:substdefault "[current]"} {-literal "[current]"} {-c:substdefault "[my c]"} @@ -525,6 +527,10 @@ {{-s:substdefault "[current]"} {-literal "[current]"} {-c:substdefault "[my c]"} {-d:integer,substdefault "$d"} -switch:switch -optflag x y:integer {z 1}} \ "query method parameter" + + ? {D public method foo {s:switch} {return 1}} \ + {invalid parameter type "switch" for argument s; type "switch" only allowed for non-positional arguments} + D public method foo {a b {-c 1} {-d} x {-end 100}} { set result [list] foreach v [[current class] info method args [current method]] {