#3714 [lindex] accepts bad index

obsolete: 8.5a6
closed-fixed
5
2007-09-03
2007-05-14
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

  • Donal K. Fellows

    • 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
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks