| Ticket UUID: | 2028793 | ||
| Title: | Namespace dependence of interp alias | ||
| Type: | Bug | Created on: | 2008-07-26 15:36:10 |
| Submitter: | lars_h | Assigned to: | hobbs |
| Subsystem: | 20. [interp] | Severity: | |
| Priority: | 5 Medium | Last modified: | 2012-05-30 19:25:27 |
| Status: | Open | Closed by: | |
| Resolution: | None | Closed on: | |
| Version: | obsolete: 8.5.11 | ||
| Description: | ||||
This is probably missing documentation rather than an actual bug, but it's nonetheless rather strange behavior.
% namespace eval test {interp alias {} foo {} list "From foo"; interp alias {} test::foo {} list "From test::foo"}
test::foo
% foo
{From foo}
% test::foo
Error: invalid command name "test::foo"
% info commands test::*
% namespace children test
::test::test
% info commands test::test::*
::test::test::foo
% ::test::test::foo
{From test::foo}
The behaviour, which is inherited from Tcl_CreateObjCommand, is:
- aliases whose srcCmd does not contain a namespace separator are created in the :: namespace.
- aliases whose srcCmd contains a namespace separator are created relative to the current namespace context (in the interpreter where the command is being created!). As in the above example, a not fully qualified name is resolved relative to the current namespace (::test) even if the target namespace (::test::test) doesn't exist yet!
This is rather different from [proc], but I notice when experimenting with the issue that [rename] and [namespace ensemble create -command] are similarly capable of creating namespaces.
| ||||
| User Comments: | ||||
dkf added on 2012-05-30 17:53:40:
The most surprising part is that [interp alias] returned a name that was not fully qualified. The second most surprising is that [proc] is inconsistent with everything else. lars_h added on 2012-05-30 19:25:26:
@dkf: That the return value isn't fully qualified isn't that strange, when you consider that [interp alias] isn't supposed to return the name of the command it creates; what it in principle returns is merely a handle for the alias, which just so happens to look like the corresponding command name. The whole "handle, not command name" business is of course strange (but understandable, once you dwelve into it). As for the command creation behaviour, I would suspect it is [proc] that is principally right (two cases is less than three), and Tcl_CreateObjCommand that has a hack to make life easier for Tk and similar extensions. [interp alias] and the like are however poorly served by this hack. | ||||
