File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed
Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -1146,15 +1146,19 @@ list_slice_or_index(
11461146 n1 = len + n1 ;
11471147 if (n1 < 0 || n1 >= len )
11481148 {
1149- // For a range we allow invalid values and return an empty
1150- // list. A list index out of range is an error.
1149+ // For a range we allow invalid values and for legacy script return an
1150+ // empty list, for Vim9 script start at the first item.
1151+ // A list index out of range is an error.
11511152 if (!range )
11521153 {
11531154 if (verbose )
11541155 semsg (_ (e_listidx ), (long )n1_arg );
11551156 return FAIL ;
11561157 }
1157- n1 = n1 < 0 ? 0 : len ;
1158+ if (in_vim9script ())
1159+ n1 = n1 < 0 ? 0 : len ;
1160+ else
1161+ n1 = len ;
11581162 }
11591163 if (range )
11601164 {
Original file line number Diff line number Diff line change @@ -42,6 +42,23 @@ func Test_list_slice()
4242 let l [:1 ] += [1 , 2 ]
4343 let l [2 :] -= [1 ]
4444 call assert_equal ([2 , 4 , 2 ], l )
45+
46+ let lines = << trim END
47+ VAR l = [1 , 2 ]
48+ call assert_equal ([1 , 2 ], l [:])
49+ call assert_equal ([2 ], l [-1 : -1 ])
50+ call assert_equal ([1 , 2 ], l [-2 : -1 ])
51+ END
52+ call CheckLegacyAndVim9Success (lines )
53+
54+ let l = [1 , 2 ]
55+ call assert_equal ([], l [-3 : -1 ])
56+
57+ let lines = << trim END
58+ var l = [1 , 2 ]
59+ assert_equal ([1 , 2 ], l [-3 : -1 ])
60+ END
61+ call CheckDefAndScriptSuccess (lines )
4562endfunc
4663
4764" List identity
Original file line number Diff line number Diff line change @@ -755,6 +755,8 @@ static char *(features[]) =
755755
756756static int included_patches [] =
757757{ /* Add new patch number below this line */
758+ /**/
759+ 3336 ,
758760/**/
759761 3335 ,
760762/**/
You can’t perform that action at this time.
0 commit comments