Index: library/nx/nx.tcl =================================================================== diff -u -r7e20ec3d04d3b6a0789c26b4e77a2291df02f609 -rf6ddb05b0fe131474053d905d3cf6b581a07488e --- library/nx/nx.tcl (.../nx.tcl) (revision 7e20ec3d04d3b6a0789c26b4e77a2291df02f609) +++ library/nx/nx.tcl (.../nx.tcl) (revision f6ddb05b0fe131474053d905d3cf6b581a07488e) @@ -1833,11 +1833,11 @@ {trace none} } - ::nx::VariableSlot public method setCheckedInstVar {-nocomplain:switch object value} { + ::nx::VariableSlot public method setCheckedInstVar {-nocomplain:switch -allowpreset:switch object value} { - #if {[::nsf::var::exists $object ${:name}] && !$nocomplain} { - # return -code error "object $object has already an instance variable named '${:name}'" - #} + if {!$allowpreset && [::nsf::var::exists $object ${:name}] && !$nocomplain} { + return -code error "object $object has already an instance variable named '${:name}'" + } set options [:getParameterOptions -withMultiplicity true] if {[llength $options]} { @@ -2234,9 +2234,9 @@ } if {![info exists trace] && [info exists :trace] && ${:trace} ne "none"} { - set trace ${:trace} + set trace ${:trace} } - if {$initblock eq "" && !$configurable && !$incremental + if {$initblock eq "" && !$configurable && !$incremental && $accessor eq "none" && ![info exists trace]} { # # Slot-less variable @@ -2292,9 +2292,14 @@ if {$nocomplain} {$slot eval {set :nocomplain 1}} if {!$configurable} {$slot eval {set :configurable false}} if {[info exists defaultValue]} { + # # We could consider calling "configure" instead, but that would - # not work for true "variable" handlers - $slot setCheckedInstVar -nocomplain=$nocomplain [self] $defaultValue + # not work for true "variable" handlers. + # + # In case a get trace is activated, don't compain about + # pre-existing variables, which might be set via traces. + set allowpreset [expr {"get" in [$slot cget -trace] && [nsf::var::exists [self] $name]}] + $slot setCheckedInstVar -allowpreset=$allowpreset -nocomplain=$nocomplain [self] $defaultValue #set :__initblock($name) 1 } Index: tests/parameters.test =================================================================== diff -u -r7e20ec3d04d3b6a0789c26b4e77a2291df02f609 -rf6ddb05b0fe131474053d905d3cf6b581a07488e --- tests/parameters.test (.../parameters.test) (revision 7e20ec3d04d3b6a0789c26b4e77a2291df02f609) +++ tests/parameters.test (.../parameters.test) (revision f6ddb05b0fe131474053d905d3cf6b581a07488e) @@ -1335,7 +1335,7 @@ # ::nx::Object create o { :object property -accessor public -trace default a { - :public object method value=default {obj var} {puts stderr V=DEFAULT; return 4 } + :public object method value=default {obj var} {return 4 } } :object property -accessor public -trace get b { :public object method value=get {obj var} { return 44 } @@ -1409,8 +1409,9 @@ ? {o eval {info exists :a}} 0 ? {o eval {info exists :b}} 0 - ? {o object property -trace get {b:integer 0} { }} "" + ? {o object property -trace get {b:integer 123} { }} "" ? {o eval {info exists :b}} 1 + ? {o object property -trace get {b:integer hello} { }} {expected integer but got "hello" for parameter "b"} ? {o eval {info exists :c}} 0 ? {o object property -trace {default get} c { }} "'-trace default' and '-trace get' can't be used together"