Patch 8.2.3266
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)
Files:      src/vim9compile.c, src/testdir/test_vim9_assign.vim


*** ../vim-8.2.3265/src/vim9compile.c   2021-07-31 22:51:06.930754925 +0200
--- src/vim9compile.c   2021-08-01 13:15:18.546323206 +0200
***************
*** 6536,6554 ****
      {
        size_t      varlen = lhs->lhs_varlen;
        int         c = var_start[varlen];
        char_u      *p = var_start;
        garray_T    *stack = &cctx->ctx_type_stack;
  
!       // Evaluate "ll[expr]" of "ll[expr][idx]"
        var_start[varlen] = NUL;
!       if (compile_expr0(&p, cctx) == OK && p != var_start + varlen)
        {
            // this should not happen
!           emsg(_(e_missbrac));
!           var_start[varlen] = c;
            return FAIL;
        }
-       var_start[varlen] = c;
  
        lhs->lhs_type = stack->ga_len == 0 ? &t_void
                              : ((type_T **)stack->ga_data)[stack->ga_len - 1];
--- 6536,6560 ----
      {
        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;
+       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;
!       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
!           if (res != FAIL)
!               emsg(_(e_missbrac));
            return FAIL;
        }
  
        lhs->lhs_type = stack->ga_len == 0 ? &t_void
                              : ((type_T **)stack->ga_data)[stack->ga_len - 1];
*** ../vim-8.2.3265/src/testdir/test_vim9_assign.vim    2021-07-31 
22:51:06.930754925 +0200
--- src/testdir/test_vim9_assign.vim    2021-08-01 13:14:37.674270249 +0200
***************
*** 466,471 ****
--- 466,477 ----
    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 = {}
*** ../vim-8.2.3265/src/version.c       2021-08-01 12:44:31.856542627 +0200
--- src/version.c       2021-08-01 13:10:22.061666933 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3266,
  /**/

-- 
Eight Megabytes And Continually Swapping.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202108011117.171BHwEk228398%40masaka.moolenaar.net.

Raspunde prin e-mail lui