Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2022-09-21
13:15 • Closed ticket [c0bc269178]: switch -regexp -matchvar -indexvar broken when optio... artifact: a9ddb08836 user: jan.nijtmans
12:55
Fix [c0bc269178]: switch -regexp -matchvar -indexvar broken when optional subexpression does not mat... check-in: 92ab43ecd6 user: jan.nijtmans tags: core-8-6-branch
2022-09-20
20:44 • Pending ticket [c0bc269178]: switch -regexp -matchvar -indexvar broken when opti... artifact: 45afa2d005 user: jan.nijtmans
20:42
Proposed fix for [c0bc269178], with testcase closed check-in: ea165f0333 user: jan.nijtmans tags: bug-c0bc269178
19:06 • Ticket [c0bc269178] switch -regexp -matchvar -indexvar broken when optional sube... artifact: 5603d59098 user: dgp
18:50 • Ticket [c0bc269178]: 6 changes artifact: 81fe00d01d user: apnadkarni
18:40 • New ticket [c0bc269178]. artifact: ab139a23a5 user: apnadkarni

switch -regexp -matchvar -indexvar broken when optional subexpression does not match

Closed / Fixedc0bc269178df938974e19cbe60e69fc0e711da5fCreated 4 years agoUpdated 4 years ago
Descriptionmarkdown2022-09-20 18:40:42

The third element of m below should be the empty string as the (b)? is not matched.

% switch -regexp -matchvar m -indexvar i ac {
{(a)(b)?(c)} {puts m:$m; puts i:$i}
}
m:ac a ac c
i:{0 1} {0 0} {-1 -1} {1 1}
% info patch
8.7a6

core-8-6-branch also exhibits this bug.

However, 8.6.12 shows correct behavior

D:\src\ruff\doc\nroff>d:\tcl\magic\bin\tclsh.exe
% switch -regexp -matchvar m -indexvar i ac {
{(a)(b)?(c)} {puts m:$m; puts i:$i}
}
m:ac a {} c
i:{0 1} {0 0} {-1 -1} {1 1}
% info patch
8.6.12

So clearly something was broken post-8.6.12 release.

Referenced by2
  • 92ab43ecd6Fix [c0bc269178]: switch -regexp -matchvar -indexvar broken when optional subexpression does not match check-in2022-09-21 12:55:59
  • ea165f0333Proposed fix for [c0bc269178], with testcase check-in2022-09-20 20:42:30
apnadkarnimarkdown2022-09-20 18:50:44

The bug seems to have been introduced with this checkin on this line.

However, it seems a deliberate change so not clear to me that just reverting is the correct fix.

/Ashok

dgpplain2022-09-20 19:06:49
How did Tcl behave in release 8.6.10 ?

See TIP 623 for more background.
jan.nijtmanswiki2022-09-20 20:44:39

Proposed fix [here]

Thanks for the report, and for the testcase!

jan.nijtmanswiki2022-09-21 13:15:16

Fix committed [here]

Log in (anonymous is fine) to add a comment.