Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2007-03-01
23:35 • Closed ticket [1671138fff]: foreach: empty var list -> inf loop plus 2 ot... artifact: 0b97fc8d9f user: dkf
23:02 • Open ticket [1671138fff]. artifact: 3072bef990 user: dgp
17:16 • Closed ticket [1671138fff]. artifact: a823c99278 user: dkf
17:09 • Ticket [1671138fff]: 5 changes artifact: 0251130af1 user: dkf
16:23 • Ticket [1671138fff]: 4 changes artifact: a64511817b user: dkf
16:04 • Ticket [1671138fff]: 2 changes artifact: 2ebef5c115 user: dkf
2007-02-28
18:58 • New ticket [1671138fff]. artifact: 1dbc531a4e user: dgp

foreach: empty var list -> inf loop

Closed / Fixed1671138fffffffffffffffffffffffffffffffffCreated 20 years agoUpdated 20 years ago
Descriptionplain2007-02-28 18:58:55
This script hangs Tcl:

proc demo {} {
    foreach {} x {}
}
demo

By contrast, the non-compiled
[foreach] does this:

% foreach {} x {}
foreach varlist is empty

I'm not convinced that an error
is really the right response, but
infinite loop is definitely wrong.
dkf Ticket [1671138fff]: 2 changes [History diff]2007-03-01 16:04:35
dkfplain2007-03-01 16:23:10
Logged In: YES 
user_id=79902
Originator: NO

There is a way of detecting the difference without a loop:
  % proc foo {} {foreach {} x {error bar}}; foo
  bar
  % foreach {} x {error bar}
  foreach varlist is empty
Proposed fix: detect the empty-var-list case and don't compile.
dkfplain2007-03-01 17:09:17
Logged In: YES 
user_id=79902
Originator: NO

Fixed in HEAD. Backport needed.
dkfplain2007-03-01 17:16:49
Logged In: YES 
user_id=79902
Originator: NO

Backported.
dgpplain2007-03-01 23:02:20
Logged In: YES 
user_id=80530
Originator: YES


New test fails in 8.4.15:

==== foreach-9.1 compiled empty var list FAILED
==== Contents of test case:

    proc foo {} {
        foreach {} x {
            error "reached body"
        }
    }
    list [catch { foo } msg] $msg

---- Result was:
1 {}
---- Result should have been (exact matching):
1 {foreach varlist is empty}
==== foreach-9.1 FAILED
dkf Closed ticket [1671138fff]. [History diff]2007-03-01 23:35:14
Log in (anonymous is fine) to add a comment.