Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 4df28275d7c1975f1ab195fe58a2c61bf3da5a04db572cf1a1e995ee33536cf3
Ticket: 58fa7cc7f88d70c467ccf57fac9dbc532509277f
Callback for unset trace on namespace variable has inexplicable effect on its visibility
User & Date: erikleunissen on 2025-02-20 10:04:51
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    The script below exercises two different inexplicable issues:
    
    1. (Cases A1+B1 below)
       The variable x is unset, the trace callback redefines x, but x does not
       become visible. Only if the callback command is called another time
       (directly), the namespace variable becomes visible again.
    
    2. (Case A2)
       The namespace variable (with the same initial visibility as case A1) is
       unset but this does not trigger the callback command.
    
    This issue impedes the implementation of redefining namespace variables in project tk_collect_test_utils, forcing that it reverts to a less effective method.
    --
    
    namespace eval ::child {
        variable x
        proc callback {args} {
    	if {[llength $args] > 0} {
    	    puts "After callback triggered by unset trace"
    	} else {
    	    puts "After callback invoked directly (not as a trace callback)"
    	}
    	variable x; # restore namespace variable
        }
        trace add variable x unset [list ::child::callback]
    }
    
    # Experiment with different invocations of the callback proc
    
    # Case 0: visibility of the namespace variable
    puts "O. Initial situation\n|[namespace inscope ::child [list info vars x]]|"
    
    # Case A1. let "unset" trigger the callback
    puts -nonewline "\nA1. "
    namespace inscope ::child {unset -nocomplain x}
    puts "|[namespace inscope ::child [list info vars x]]|"
    
    # Case B1. invoke "callback" directly, i.e. not as a callback command
    puts -nonewline "\nB1. "
    ::child::callback
    puts "|[namespace inscope ::child [list info vars x]]|"
    
    # Repeat A. and B. and see the different results
    
    # Case A2: should trigger the callback as in A1, but it doesn't
    puts -nonewline "\nA2. "
    namespace inscope ::child {unset -nocomplain x}
    puts "|[namespace inscope ::child [list info vars x]]|"
    
    # Case B2: as B1
    puts -nonewline "\nB2. "
    ::child::callback
    puts "|[namespace inscope ::child [list info vars x]]|"
    
    # EOF
    
  5. foundin changed to: "trunk"
  6. is_private changed to: "0"
  7. login: "erikleunissen"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "609f4c7ecf7dbb7a46acdc7eb164753d196088a6"
  10. resolution changed to: "None"
  11. severity changed to: "Important"
  12. status changed to: "Open"
  13. submitter changed to: "erikleunissen"
  14. subsystem changed to: "21. [namespace]"
  15. title changed to:
    Callback for unset trace on namespace variable has inexplicable effect on its visibility
    
  16. type changed to: "Bug"