Skip to content

Commit e97976b

Browse files
committed
patch 8.2.3266: Vim9: assignment with two indexes may check next line
Problem: Vim9: assignment with two indexes may check next line. Solution: Limit the number of lines to avoid checking the next line when assiging to a LHS subscript. (closes #8660)
1 parent 78ba933 commit e97976b

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/testdir/test_vim9_assign.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,12 @@ def Test_assign_index()
466466
d3.one.two.three = 123
467467
assert_equal({one: {two: {three: 123}}}, d3)
468468

469+
# should not read the next line when generating "a.b"
470+
var a = {}
471+
a.b = {}
472+
a.b.c = {}
473+
->copy()
474+
469475
lines =<< trim END
470476
var d3: dict<dict<number>>
471477
d3.one = {}

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3266,
758760
/**/
759761
3265,
760762
/**/

src/vim9compile.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6536,19 +6536,25 @@ compile_load_lhs(
65366536
{
65376537
size_t varlen = lhs->lhs_varlen;
65386538
int c = var_start[varlen];
6539+
int lines_len = cctx->ctx_ufunc->uf_lines.ga_len;
65396540
char_u *p = var_start;
65406541
garray_T *stack = &cctx->ctx_type_stack;
6542+
int res;
65416543

6542-
// Evaluate "ll[expr]" of "ll[expr][idx]"
6544+
// Evaluate "ll[expr]" of "ll[expr][idx]". End the line with a NUL and
6545+
// limit the lines array length to avoid skipping to a following line.
65436546
var_start[varlen] = NUL;
6544-
if (compile_expr0(&p, cctx) == OK && p != var_start + varlen)
6547+
cctx->ctx_ufunc->uf_lines.ga_len = cctx->ctx_lnum + 1;
6548+
res = compile_expr0(&p, cctx);
6549+
var_start[varlen] = c;
6550+
cctx->ctx_ufunc->uf_lines.ga_len = lines_len;
6551+
if (res == FAIL || p != var_start + varlen)
65456552
{
65466553
// this should not happen
6547-
emsg(_(e_missbrac));
6548-
var_start[varlen] = c;
6554+
if (res != FAIL)
6555+
emsg(_(e_missbrac));
65496556
return FAIL;
65506557
}
6551-
var_start[varlen] = c;
65526558

65536559
lhs->lhs_type = stack->ga_len == 0 ? &t_void
65546560
: ((type_T **)stack->ga_data)[stack->ga_len - 1];

0 commit comments

Comments
 (0)