Index: TODO =================================================================== diff -u -r7401c1c91b67a9adc5b3c1a9049a37a9d8e13c93 -rc1b0280fcc98b5ac8c94b36e274e1ae0906364d5 --- TODO (.../TODO) (revision 7401c1c91b67a9adc5b3c1a9049a37a9d8e13c93) +++ TODO (.../TODO) (revision c1b0280fcc98b5ac8c94b36e274e1ae0906364d5) @@ -4895,6 +4895,9 @@ modules using the converter - Added editor hints for a more uniform appearance +nx.tcl: +- raise an error, when an ensemble methods redefined a plain method + ======================================================================== TODO: Index: library/nx/nx.tcl =================================================================== diff -u -r17b2bed824041ef05d7739b2151882d5f9ec1f88 -rc1b0280fcc98b5ac8c94b36e274e1ae0906364d5 --- library/nx/nx.tcl (.../nx.tcl) (revision 17b2bed824041ef05d7739b2151882d5f9ec1f88) +++ library/nx/nx.tcl (.../nx.tcl) (revision c1b0280fcc98b5ac8c94b36e274e1ae0906364d5) @@ -157,8 +157,16 @@ if {[::nsf::is class $object] && !${per-object}} { set scope class set ensembleName [::nx::slotObj ${object} __$w] + if {[: ::nsf::methods::class::info::method exists $w] + && [: ::nsf::methods::class::info::method type $w] ne "alias"} { + return -code error "refuse to overwrite method $w; delete/rename method first." + } } else { set scope object + if {[: ::nsf::methods::object::info::method exists $w] + && [: ::nsf::methods::object::info::method type $w] ne "object"} { + return -code error "refuse to overwrite object method $w; delete/rename object method first." + } set ensembleName ${object}::$w } #puts stderr "NX check $scope $object info methods $path @ <$w> cmd=[info command $w] obj?[nsf::object::exists $ensembleName] " @@ -2652,3 +2660,9 @@ puts stderr "======= nx loaded" } +# +# Local variables: +# mode: tcl +# tcl-indent-level: 2 +# indent-tabs-mode: nil +# End: Index: tests/submethods.test =================================================================== diff -u -r4bc60e16c10fdbbb640b3019d4bdebdc469fdf55 -rc1b0280fcc98b5ac8c94b36e274e1ae0906364d5 --- tests/submethods.test (.../submethods.test) (revision 4bc60e16c10fdbbb640b3019d4bdebdc469fdf55) +++ tests/submethods.test (.../submethods.test) (revision c1b0280fcc98b5ac8c94b36e274e1ae0906364d5) @@ -792,6 +792,41 @@ ? {d1 c1 baz} c1-::d1 } + +nx::test case ensemble-vs-simple-method { + + ? {nx::Class create C} ::C + ? {C public method foo {args} {return foo/1}} "::nsf::classes::C::foo" + ? {C public method "foo x" {args} {return foo/2}} \ + {refuse to overwrite method foo; delete/rename method first.} + ? {C public method "foo x y" {args} {return foo/3}} \ + {refuse to overwrite method foo; delete/rename method first.} + + ? {C public method "bar x" {args} {return bar/2}} {::C::slot::__bar::x} + ? {C public method "bar x y" {args} {return foo/3}} \ + {refuse to overwrite cmd ::C::slot::__bar::x; delete/rename it before overwriting} + + C create c1 + + ? {c1 foo x y z} "foo/1" + ? {c1 bar x y z} "bar/2" + + + ? {nx::Object create o1} ::o1 + ? {o1 public object method foo {args} {return foo/1}} "::o1::foo" + ? {o1 public object method "foo x" {args} {return foo/2}} \ + {refuse to overwrite object method foo; delete/rename object method first.} + ? {o1 public object method "foo x y" {args} {return foo/3}} \ + {refuse to overwrite object method foo; delete/rename object method first.} + + ? {o1 public object method "bar x" {args} {return bar/2}} {::o1::bar::x} + ? {o1 public object method "bar x y" {args} {return foo/3}} \ + {refuse to overwrite cmd ::o1::bar::x; delete/rename it before overwriting} + + ? {o1 foo x y z} "foo/1" + ? {o1 bar x y z} "bar/2" +} + # # Local variables: # mode: tcl