Skip to content
Tcl Source Code View Ticket
Login

View Ticket

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.