changeset 25459:9adaa0c056c7 v8.2.3266

patch 8.2.3266: Vim9: assignment with two indexes may check next line Commit: https://github.com/vim/vim/commit/e97976baa7a74fbbe0cfecd1943fe1c5f9dfba4f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 1 13:17:17 2021 +0200 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)
author Bram Moolenaar <Bram@vim.org>
date Sun, 01 Aug 2021 13:30:04 +0200
parents cf9a5512f4be
children 2e4c691247c1
files src/testdir/test_vim9_assign.vim src/version.c src/vim9compile.c
diffstat 3 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -466,6 +466,12 @@ def Test_assign_index()
   d3.one.two.three = 123
   assert_equal({one: {two: {three: 123}}}, d3)
 
+  # should not read the next line when generating "a.b"
+  var a = {}
+  a.b = {}
+  a.b.c = {}
+          ->copy()
+
   lines =<< trim END
       var d3: dict<dict<number>>
       d3.one = {}
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3266,
+/**/
     3265,
 /**/
     3264,
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -6536,19 +6536,25 @@ compile_load_lhs(
     {
 	size_t	    varlen = lhs->lhs_varlen;
 	int	    c = var_start[varlen];
+	int	    lines_len = cctx->ctx_ufunc->uf_lines.ga_len;
 	char_u	    *p = var_start;
 	garray_T    *stack = &cctx->ctx_type_stack;
-
-	// Evaluate "ll[expr]" of "ll[expr][idx]"
+	int	    res;
+
+	// Evaluate "ll[expr]" of "ll[expr][idx]".  End the line with a NUL and
+	// limit the lines array length to avoid skipping to a following line.
 	var_start[varlen] = NUL;
-	if (compile_expr0(&p, cctx) == OK && p != var_start + varlen)
+	cctx->ctx_ufunc->uf_lines.ga_len = cctx->ctx_lnum + 1;
+	res = compile_expr0(&p, cctx);
+	var_start[varlen] = c;
+	cctx->ctx_ufunc->uf_lines.ga_len = lines_len;
+	if (res == FAIL || p != var_start + varlen)
 	{
 	    // this should not happen
-	    emsg(_(e_missbrac));
-	    var_start[varlen] = c;
+	    if (res != FAIL)
+		emsg(_(e_missbrac));
 	    return FAIL;
 	}
-	var_start[varlen] = c;
 
 	lhs->lhs_type = stack->ga_len == 0 ? &t_void
 			      : ((type_T **)stack->ga_data)[stack->ga_len - 1];