#3714 [lindex] accepts bad index

obsolete: 8.5a6
closed-fixed
Kevin B KENNY
5
2007-09-03
2007-05-14
Lars Hellström
No

Mistyping [lindex] where I meant [linsert], I discovered the following behaviour: [lindex {} end foo] does not throw an error, whereas [lindex {} foo] does! Or as an example session:

% info patchlevel
8.5a6
% lindex {} foo
bad index "foo": must be integer?[+-]integer? or end?[+-]integer?
% lindex {} end foo
% lindex a end foo
bad index "foo": must be integer?[+-]integer? or end?[+-]integer?
% lindex {} 0 foo
% lindex {} -1 foo
% lindex {} foo foo
bad index "foo": must be integer?[+-]integer? or end?[+-]integer?

This is probably due to lines 1108-1115 of tclListObj.c (v 1.46): once an out-of-bounds index is encountered, remaining indices are ignored. Indeed,

% lindex a 1 foo
% lindex a 0 foo
bad index "foo": must be integer?[+-]integer? or end?[+-]integer?
% lindex a -1 foo

Discussion

    • labels: 105658 --> 14. List Object
    • assigned_to: dkf --> hobbs
     
  • Don Porter
    Don Porter
    2007-05-14

    • assigned_to: hobbs --> kennykb
     
  • Kevin B KENNY
    Kevin B KENNY
    2007-09-03

    • status: open --> closed-fixed