Tcl Source Code

View Ticket
Login
Ticket UUID: 66c2e8c97414a1f908d48753490526bb1cded0f4
Title: Interpreter name resolution has problems with namespaces
Type: Bug Created on: 2020-07-21 12:15:47
Submitter: kjnash Assigned to: nobody
Subsystem: 20. [interp] Severity: Important
Priority: 5 Medium Last modified: 2020-07-21 12:15:47
Status: Open Closed by: nobody
Resolution: None Closed on:
Version: 8.6.10
Description:
The interp command recognizes "foo" and "::foo" as different interpreter names.  However, the two interpreters have the same interpreter command.  When "::foo" is created below, the command for interpreter "foo" is overwritten and so interpreter "foo" is deleted.

The problem is that, because "interp" creates a command for each interpreter, its rules for name resolution should not differ from the rules for name resolution of commands.

Suggested remedy: "interp" should recognize interpreter names as equal only if their fully-qualified namespace names are equal.

When there are multiple levels of interpreters, e.g. a slave ::foo with its own slave {::foo ::bar}, the name in the master interpreter is a list, and each element in the list should be compared with its peers by their fully-qualified namespace names.  This ensures the same outcome if interpreter {::foo ::bar} is created in the master, as if interpreter ::bar is created in the slave ::foo.

The usual, expected behavior:

% interp create foo
foo
% interp create foo
interpreter named "foo" already exists, cannot create

The unexpected behavior:

% interp create foo
foo
% interp create ::foo
::foo
% interp slaves
::foo

Check that the interpreter really has been replaced:

% interp create foo
foo
% foo eval set a abc
abc
% foo eval set a
abc
% interp create ::foo
::foo
% interp slaves
::foo
% foo eval set a
can't read "a": no such variable

For maximum surprise, move the first interpreter's command so that interpreters foo and ::foo can coexist:

% interp create foo
foo
% interp eval foo set a abc
abc
% interp eval foo set a
abc
% rename foo moved
% interp create ::foo
::foo
% interp slaves
::foo foo
% interp eval foo set a
abc
% interp eval ::foo set a
can't read "a": no such variable
% moved eval set a
abc