1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
# -*- Tcl -*-
#
# testing cmd resolution
#
package prefer latest
package require nx
package require XOTcl
package require nx::test
#
# Tests leading to bug-report concerning shared cmd literals in the
# global literal pool: https://core.tcl-lang.org/tcl/tktview?name=d4e7780ca1
#
::nx::test case cmd-resolver-1 {
namespace eval ::xowiki {}
nx::Class create ::xowiki::C {
:public method foo {} {return [self]}
:create c1
}
#
# By calling foo, the body of this method is compiled, and the cmd
# literal "self" is resolved against "nx::self" in the namespace
# "::xowiki".
#
? {c1 foo} ::c1
xotcl::Class create xowiki::Link
xowiki::Link instproc init {} {
#namespace which self
catch {set c [self class]} errorMsg
#nsf::__db_show_obj self
set class [self class]
}
# When creating an instance of the xotcl class "xowiki::Link", the
# constructor "init" is compiled. In this step the command literal
# "self" in the constructor has to be resolved against the
# underlying object system (here xotcl::self) without interacting
# with "nx::self" from above.
? {xowiki::Link create l1} ::l1
# xowiki::Link ::nsf::methods::class::info::method disassemble init
}
::nx::test case cmd-resolver-2 {
namespace eval ::xowiki {}
#
# This test is similar to cmd-resolver-1, be we test now for "self"
# and "next"
#
nx::Class create xowiki::C1 {
:public method foo {x y} {set s [self]; return $x-$y-C1}
}
nx::Class create xowiki::C2 -superclass xowiki::C1 {
:public method foo {x y} {return [next [list $x $y]]}
}
#
# During the execution of the command below, "next" and "self" are
# added to the global command literal pool for the namespace
# "xowiki".
#
? {[xowiki::C2 new] foo 1 2} 1-2-C1
#
# Create similar classes for XOTcl
#
xotcl::Class create xowiki::X1
xowiki::X1 instproc foo {x y} {
return $x-$y-[self class]
}
xotcl::Class create xowiki::X2 -superclass xowiki::X1
xowiki::X2 instproc foo {x y} {
return [next $x $y]
}
#
# Bytecompile and execute the "foo" methods containing the cmd
# literals "self" and "next" in the xotcl classes
#
? {[xowiki::X2 new] foo 1 2} 1-2-::xowiki::X1
#
# Any kind of shimmering in the global literal pool would no help,
# since C2 still needs the nx variants of "self" and "next".
#
? {[xowiki::C2 new] foo 1 2} 1-2-C1
# xowiki::Link ::nsf::methods::class::info::method disassemble init
}
#
# Local variables:
# mode: tcl
# tcl-indent-level: 2
# indent-tabs-mode: nil
# End:
|