@ -8,7 +8,7 @@
# (C) 2024
#
# @@ Meta Begin
# Application punk::lib 0.4.3
# Application punk::lib 0.5.0
# Meta platform tcl
# Meta license BSD
# @@ Meta End
@ -18,7 +18,7 @@
# doctools header
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
#*** !doctools
#[manpage_begin punkshell_module_punk::lib 0 0.4.3 ]
#[manpage_begin punkshell_module_punk::lib 0 0.5.0 ]
#[copyright "2024"]
#[titledesc {punk general utility functions}] [comment {-- Name section and table of contents description --}]
#[moddesc {punk library}] [comment {-- Description at end of page heading --}]
@ -292,7 +292,7 @@ tcl::namespace::eval punk::lib::check {
if {$replversion eq ""} {
#not loaded - determine what version would be provided, without loading it:
#an unsatisfiable require triggers the package unknown scan (registering ifneeded
#scripts) then fails before any load (0.4.3 dev modules are alpha - below 999999).
#scripts) then fails before any load (0.5.0 dev modules are alpha - below 999999).
catch {package require punk::repl 999999}
set available [package versions punk::repl]
if {[llength $available]} {
@ -307,6 +307,97 @@ tcl::namespace::eval punk::lib::check {
return [dict create bug $bug bugref f10d91c2d3 description $description level major mitigated $mitigated mitigation $mitigation]
}
#pure classifier, separated for testability - facts in, verdict out.
#The bug's signature is a MIXTURE within one switch: the default arm reports its
#single command arm-relative (line 2 of the arm script) while arm 1 reports it
#shifted by (line of the switch command within its containing script - 1), which
#is 3 in the probe layout below. A self-consistent upstream fix of either flavour
#(uniform arm-relative, or uniform container-relative) breaks the signature and
#reports no bug - if upstream instead changes attribution semantics some other
#way, revisit this classifier.
proc tclbug_nestedswitch_tracelines_signature {arm1line defaultline} {
return [expr {$defaultline == 2 && $arm1line == 3}]
}
proc has_tclbug_nestedswitch_tracelines {} {
#Execution-trace line mis-attribution for nested single-block switch arm bodies.
#https://core.tcl-lang.org/tcl/tktview/5d5b1052280c976ea3d4 (reported by punkshell author 2025-11-10)
#For a proc without source-line correlation (e.g dynamically defined - also the regime
#module-loaded punkshell procs trace in), an arm body whose index into the split
#pattern/body list lands on a LITERAL word of the switch command (an option word, --,
#or the block itself) reports enterstep/info-frame lines shifted by (line of the switch
#command within its containing script - 1) - attributed as if the arm body began at the
#switch command's line. Arms whose index lands on a dynamic word or beyond the command's
#word count report correctly arm-relative - so WHICH arms mismark varies with the option
#words used. Verified identical on Tcl 8.6.17 / 8.7a6 / 9.0.3 (2026-07-14).
#Standalone repro/write-up: scriptlib/developer/tcl_switch_traceline_repro.tcl
#
#Behavioural probe (no version gate needed - detection flips automatically when a fixed
#Tcl runtime is in use): a dynamically-defined proc with a nested 'switch -- $c {...}'
#is enterstep-traced once for arm 1 and once for the default arm, and the reported lines
#are matched against the characterized wrong/right signature (see the classifier above).
#
#Followup when upstream fixed (this check starts reporting bug 0 on a new Tcl release):
# - re-verify with scriptlib/developer/tcl_switch_traceline_repro.tcl on that runtime
# - flip the GAP pins in test suite ns/cmdtrace.test
# (cmdtrace_marks_nested_upstream_mismark_GAP and the fixed-canary test there)
# - update the punk::ns::cmdtrace argdoc caveat that cites the ticket
# - note the fixed-in version here
#Consumers: punk::ns::cmdtrace switch-arm line marking accuracy; 'help tcl' warning report.
set pname [namespace current]::Nestedswitch_traceline_probeproc
set lvar [namespace current]::Nestedswitch_traceline_probelines
#the body must be passed via a variable so the probe proc has no source-line
#correlation (the absolute-source regime does not exhibit the mis-attribution)
#inner switch is the 4-word shape (switch -- $string <block>): per the law, split-list
#body indices 1 and 3 are affected (they land on the literal -- and block words), so the
#middle arm exists purely to push the default arm's body to index 5 - beyond the switch
#command's word count and therefore correctly arm-relative. (A 2-arm probe would put the
#default body at index 3 and BOTH arms would mismark - hiding the signature.)
set probebody {
switch -- [string index $s 0] {
a {
switch -- [string index $s 1] {
1 {
llength probemark
}
2 {
llength probeunused
}
default {
llength probemark
}
}
}
default {}
}
}
proc $pname {s} $probebody
set $lvar [list]
set handler [list ::apply [list {pname lvar args} {
set f [::tcl::info::frame -2]
if {[dict exists $f proc] && [dict get $f proc] eq $pname && [dict exists $f cmd]} {
if {[string match "llength probemark*" [dict get $f cmd]]} {
catch {lappend $lvar [dict get $f line]}
}
}
}] $pname $lvar]
set bug 0
try {
trace add execution $pname enterstep $handler
$pname a1 ;#inner arm 1
$pname a9 ;#inner default arm
lassign [set $lvar] arm1line defaultline
if {$arm1line ne "" && $defaultline ne ""} {
set bug [tclbug_nestedswitch_tracelines_signature $arm1line $defaultline]
}
} finally {
catch {trace remove execution $pname enterstep $handler}
catch {rename $pname ""}
catch {unset $lvar}
}
set description "Execution traces on a nested single-block switch mis-attribute lines for the arm bodies\nwhose split-list index lands on a literal word of the switch command (options/--/block):\nthose arms report lines as if their body began at the switch command's line, while other\narms report correctly arm-relative. Debug/trace tooling line markers (e.g punk::ns::cmdtrace)\nare wrong for the affected arms - which arms are affected varies with the switch options used."
return [dict create bug $bug bugref 5d5b1052280c976ea3d4 description $description level medium]
}
#has_libbug_* procs report bugs in bundled/vendored library packages rather than the Tcl core.
#They are surfaced through the same 'help tcl' warning report as the has_tclbug_* checks.
@ -9238,7 +9329,7 @@ namespace eval ::punk::args::register {
package provide punk::lib [tcl::namespace::eval punk::lib {
variable pkg punk::lib
variable version
set version 0.4.3
set version 0.5.0
}]
return