Patch 8.2.3113
Problem:    No error when for loop variable shadows script variable.
Solution:   Check for the error. (closes #8512)
Files:      src/eval.c, src/testdir/test_vim9_script.vim


*** ../vim-8.2.3112/src/eval.c  2021-07-05 21:41:44.782616398 +0200
--- src/eval.c  2021-07-05 22:20:09.330040863 +0200
***************
*** 1777,1783 ****
      forinfo_T *fi = (forinfo_T *)fi_void;
      int               result;
      int               flag = ASSIGN_FOR_LOOP | (in_vim9script()
!                        ? (ASSIGN_FINAL | ASSIGN_DECL | ASSIGN_NO_MEMBER_TYPE)
                         : 0);
      listitem_T        *item;
  
--- 1777,1786 ----
      forinfo_T *fi = (forinfo_T *)fi_void;
      int               result;
      int               flag = ASSIGN_FOR_LOOP | (in_vim9script()
!                        ? (ASSIGN_FINAL
!                            // first round: error if variable exists
!                            | (fi->fi_bi == 0 ? 0 : ASSIGN_DECL)
!                            | ASSIGN_NO_MEMBER_TYPE)
                         : 0);
      listitem_T        *item;
  
***************
*** 1807,1812 ****
--- 1810,1816 ----
        tv.v_lock = VAR_FIXED;
        tv.vval.v_string = vim_strnsave(fi->fi_string + fi->fi_byte_idx, len);
        fi->fi_byte_idx += len;
+       ++fi->fi_bi;
        result = ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon,
                                            fi->fi_varcount, flag, NULL) == OK;
        vim_free(tv.vval.v_string);
***************
*** 1819,1824 ****
--- 1823,1829 ----
      else
      {
        fi->fi_lw.lw_item = item->li_next;
+       ++fi->fi_bi;
        result = (ex_let_vars(arg, &item->li_tv, TRUE, fi->fi_semicolon,
                                           fi->fi_varcount, flag, NULL) == OK);
      }
*** ../vim-8.2.3112/src/testdir/test_vim9_script.vim    2021-07-05 
21:41:44.782616398 +0200
--- src/testdir/test_vim9_script.vim    2021-07-05 22:21:32.917862622 +0200
***************
*** 2533,2544 ****
  enddef
  
  def Test_for_loop_fails()
!   CheckDefFailure(['for '], 'E1097:')
!   CheckDefFailure(['for x'], 'E1097:')
!   CheckDefFailure(['for x in'], 'E1097:')
!   CheckDefFailure(['for # in range(5)'], 'E690:')
!   CheckDefFailure(['for i In range(5)'], 'E690:')
!   CheckDefFailure(['var x = 5', 'for x in range(5)'], 'E1017:')
    CheckScriptFailure(['def Func(arg: any)', 'for arg in range(5)', 'enddef', 
'defcompile'], 'E1006:')
    delfunc! g:Func
    CheckDefFailure(['for i in xxx'], 'E1001:')
--- 2533,2544 ----
  enddef
  
  def Test_for_loop_fails()
!   CheckDefAndScriptFailure2(['for '], 'E1097:', 'E690:')
!   CheckDefAndScriptFailure2(['for x'], 'E1097:', 'E690:')
!   CheckDefAndScriptFailure2(['for x in'], 'E1097:', 'E15:')
!   CheckDefAndScriptFailure(['for # in range(5)'], 'E690:')
!   CheckDefAndScriptFailure(['for i In range(5)'], 'E690:')
!   CheckDefAndScriptFailure2(['var x = 5', 'for x in range(5)', 'endfor'], 
'E1017:', 'E1041:')
    CheckScriptFailure(['def Func(arg: any)', 'for arg in range(5)', 'enddef', 
'defcompile'], 'E1006:')
    delfunc! g:Func
    CheckDefFailure(['for i in xxx'], 'E1001:')
*** ../vim-8.2.3112/src/version.c       2021-07-05 22:02:53.772180695 +0200
--- src/version.c       2021-07-05 22:09:05.215473016 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3113,
  /**/

-- 
>From "know your smileys":
 <>:-)  Bishop

 /// 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/202107052023.165KNgEd2897363%40masaka.moolenaar.net.

Raspunde prin e-mail lui