Tcl Library Source Code

View Ticket
Login
Ticket UUID: 9f1eda1887442dc98643f430a8d61455db338b1a
Title: snit -option -default won't recognize global or namespaced variables
Type: Bug Version: 2.3.2
Submitter: ron-fox Created on: 2016-09-02 13:11:25
Subsystem: snit Assigned To: wduquette
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2016-09-04 00:32:30
Resolution: None Closed By: nobody
    Closed on:
Description:
Consider the following code snippet:

package require snit
set a 1234
namespace eval b {
  variable c 5678
}

snit::type a {
  option -a -default $::a
}

snit::type b {
   option -b -default $::b::c
}


Snit will claim for both option definitions that the variable is not readable:
e.g. for type a:

 can't read "::a": no such variable


for type b:

can't read "::b::c": no such variable


The use case for this is to use a variable in Tcl in the same manner a #define is used in e.g. C

Workaround:
  Options where this is desired can be initialized in the constructor for the type e.g.

snit::type a {
  option -a 
  constructor args {
     set options(-a) $::a
     self configurelist $args
  }
}