Patch 8.2.0483
Problem:    Vim9: "let x = x + 1" does not give an error.
Solution:   Hide the variable when compiling the expression.
Files:      src/vim9compile.c, src/testdir/test_vim9_expr.vim


*** ../vim-8.2.0482/src/vim9compile.c   2020-03-29 21:38:10.277149761 +0200
--- src/vim9compile.c   2020-03-30 21:04:28.794831393 +0200
***************
*** 3685,3690 ****
--- 3685,3692 ----
      }
      else if (oplen > 0)
      {
+       int r;
+ 
        // for "+=", "*=", "..=" etc. first load the current value
        if (*op != '=')
        {
***************
*** 3717,3726 ****
            }
        }
  
!       // compile the expression
        instr_count = instr->ga_len;
        p = skipwhite(p + oplen);
!       if (compile_expr1(&p, cctx) == FAIL)
            goto theend;
  
        if (idx >= 0 && (is_decl || !has_type))
--- 3719,3734 ----
            }
        }
  
!       // Compile the expression.  Temporarily hide the new local variable
!       // here, it is not available to this expression.
!       if (idx >= 0)
!           --cctx->ctx_locals.ga_len;
        instr_count = instr->ga_len;
        p = skipwhite(p + oplen);
!       r = compile_expr1(&p, cctx);
!       if (idx >= 0)
!           ++cctx->ctx_locals.ga_len;
!       if (r == FAIL)
            goto theend;
  
        if (idx >= 0 && (is_decl || !has_type))
*** ../vim-8.2.0482/src/testdir/test_vim9_expr.vim      2020-03-29 
21:38:10.277149761 +0200
--- src/testdir/test_vim9_expr.vim      2020-03-30 21:04:54.694750516 +0200
***************
*** 738,743 ****
--- 738,745 ----
    call CheckDefFailure("let x = {'a': xxx}", 'E1001:')
    call CheckDefFailure("let x = {xxx: 8}", 'E1001:')
    call CheckDefFailure("let x = #{a: 1, a: 2}", 'E721:')
+   call CheckDefFailure("let x += 1", 'E1020:')
+   call CheckDefFailure("let x = x + 1", 'E1001:')
    call CheckDefExecFailure("let x = g:anint.member", 'E715:')
    call CheckDefExecFailure("let x = g:dict_empty.member", 'E716:')
  enddef
*** ../vim-8.2.0482/src/version.c       2020-03-30 19:30:07.133542905 +0200
--- src/version.c       2020-03-30 21:05:27.738647194 +0200
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     483,
  /**/

-- 
Vi beats Emacs to death, and then again!
                        http://linuxtoday.com/stories/5764.html

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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/202003301906.02UJ6C0F023561%40masaka.moolenaar.net.

Raspunde prin e-mail lui