Skip to content

Commit b13af50

Browse files
committed
patch 8.2.0269: Vim9: operator after list index does not work
Problem: Vim9: operator after list index does not work. (Yasuhiro Matsumoto) Solution: After indexing a list change the type to the list member type. (closes #5651)
1 parent 40d9da2 commit b13af50

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/testdir/test_vim9_expr.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,17 @@ def Test_expr6()
478478
assert_equal(2, g:anint % g:alsoint)
479479

480480
assert_equal(4, 6 * 4 / 6)
481+
482+
let x = [2]
483+
let y = [3]
484+
assert_equal(5, x[0] + y[0])
485+
assert_equal(6, x[0] * y[0])
486+
if has('float')
487+
let xf = [2.0]
488+
let yf = [3.0]
489+
assert_equal(5.0, xf[0] + yf[0])
490+
assert_equal(6.0, xf[0] * yf[0])
491+
endif
481492
enddef
482493

483494
def Test_expr6_float()
@@ -538,6 +549,10 @@ func Test_expr6_fails()
538549
call CheckDefFailure("let x = #{one: 1} / #{two: 2}", 'E1036:')
539550
call CheckDefFailure("let x = #{one: 1} % #{two: 2}", 'E1035:')
540551

552+
call CheckDefFailure("let x = 0xff[1]", 'E714:')
553+
if has('float')
554+
call CheckDefFailure("let x = 0.7[1]", 'E714:')
555+
endif
541556
endfunc
542557

543558
func Test_expr6_float_fails()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ static char *(features[]) =
742742

743743
static int included_patches[] =
744744
{ /* Add new patch number below this line */
745+
/**/
746+
269,
745747
/**/
746748
268,
747749
/**/

src/vim9compile.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,9 @@ compile_subscript(
23302330
}
23312331
else if (**arg == '[')
23322332
{
2333+
garray_T *stack;
2334+
type_T **typep;
2335+
23332336
// list index: list[123]
23342337
// TODO: more arguments
23352338
// TODO: dict member dict['name']
@@ -2346,6 +2349,14 @@ compile_subscript(
23462349

23472350
if (generate_instr_drop(cctx, ISN_INDEX, 1) == FAIL)
23482351
return FAIL;
2352+
stack = &cctx->ctx_type_stack;
2353+
typep = ((type_T **)stack->ga_data) + stack->ga_len - 1;
2354+
if ((*typep)->tt_type != VAR_LIST && *typep != &t_any)
2355+
{
2356+
emsg(_(e_listreq));
2357+
return FAIL;
2358+
}
2359+
*typep = (*typep)->tt_member;
23492360
}
23502361
else if (**arg == '.' && (*arg)[1] != '.')
23512362
{

0 commit comments

Comments
 (0)