aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jim-namespace.c1
-rw-r--r--nshelper.tcl3
-rw-r--r--tests/namespace.test15
3 files changed, 18 insertions, 1 deletions
diff --git a/jim-namespace.c b/jim-namespace.c
index 600f8ec..bcc7259 100644
--- a/jim-namespace.c
+++ b/jim-namespace.c
@@ -268,7 +268,6 @@ static int JimNamespaceCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Jim_SetResult(interp, Jim_NamespaceQualifiers(interp, argv[2]));
return JIM_OK;
- case OPT_IMPORT:
case OPT_EXPORT:
return JIM_OK;
diff --git a/nshelper.tcl b/nshelper.tcl
index 33acb51..d0cb35a 100644
--- a/nshelper.tcl
+++ b/nshelper.tcl
@@ -63,6 +63,9 @@ proc {namespace import} {args} {
foreach pattern $args {
foreach cmd [info commands [namespace canon $current $pattern]] {
+ if {[namespace qualifiers $cmd] eq $current} {
+ return -code error "import pattern \"$pattern\" tries to import from namespace \"$current\" into itself"
+ }
alias ${current}::[namespace tail $cmd] $cmd
}
}
diff --git a/tests/namespace.test b/tests/namespace.test
index 98acf3e..090fcf0 100644
--- a/tests/namespace.test
+++ b/tests/namespace.test
@@ -470,6 +470,21 @@ test namespace-11.1 {command caching} {
lappend result [ns1::cmd2]
} {ns1 global}
+test namespace-12.1 {namespace import} {
+ namespace eval test_ns_scope1 {
+ proc a {} { return a }
+ namespace export a
+ }
+ namespace eval test_ns_scope2 {
+ namespace import ::test_ns_scope1::a
+ a
+ }
+} {a}
+
+test namespace-12.2 {namespace import recursive} -body {
+ namespace import *
+} -returnCodes error -match glob -result {import pattern "*" tries to import from namespace "*" into itself}
+
foreach cmd [info commands test_ns_*] {
rename $cmd ""
}