Tcl Source Code

View Ticket
Login
Ticket UUID: c0bc269178df938974e19cbe60e69fc0e711da5
Title: switch -regexp -matchvar -indexvar broken when optional subexpression does not match
Type: Bug Created on: 2022-09-20 18:40:42
Submitter: apnadkarni Assigned to: jan.nijtmans
Subsystem: 18. Commands M-Z Severity: Minor
Priority: 7 High Last modified: 2022-09-21 13:15:16
Status: Closed Closed by: jan.nijtmans
Resolution: Fixed Closed on: 2022-09-21 13:15:16
Version: 8.6.13
Description:

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.

User Comments:
apnadkarni added on 2022-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


dgp added on 2022-09-20 19:06:49:
How did Tcl behave in release 8.6.10 ?

See TIP 623 for more background.

jan.nijtmans added on 2022-09-20 20:44:39:

Proposed fix [ea165f0333f93885|here]

Thanks for the report, and for the testcase!


jan.nijtmans added on 2022-09-21 13:15:16:

Fix committed [92ab43ecd6cdd9a4|here]