Patch 8.2.2080
Problem:    Vim9: no proper error message for using s:var in for loop.
Solution:   Give a specific error.
Files:      src/vim9compile.c, src/testdir/test_vim9_script.vim


*** ../vim-8.2.2079/src/vim9compile.c   2020-12-02 13:23:30.733664326 +0100
--- src/vim9compile.c   2020-12-02 14:10:07.164372339 +0100
***************
*** 6617,6622 ****
--- 6617,6628 ----
                goto failed;
            }
  
+           if (STRNCMP(name, "s:", 2) == 0)
+           {
+               semsg(_(e_cannot_declare_script_variable_in_function), name);
+               goto failed;
+           }
+ 
            // Reserve a variable to store "var".
            // TODO: check for type
            var_lvar = reserve_local(cctx, arg, varlen, FALSE, &t_any);
*** ../vim-8.2.2079/src/testdir/test_vim9_script.vim    2020-12-02 
13:23:30.733664326 +0100
--- src/testdir/test_vim9_script.vim    2020-12-02 14:23:49.317772055 +0100
***************
*** 1884,1889 ****
--- 1884,1910 ----
    CheckDefFailure(['for i in range(3)', 'echo 3'], 'E170:')
  enddef
  
+ def Test_for_loop_script_var()
+   # cannot use s:var in a :def function
+   CheckDefFailure(['for s:var in range(3)', 'echo 3'], 'E1101:')
+ 
+   # can use s:var in Vim9 script, with or without s:
+   var lines =<< trim END
+     vim9script
+     var total = 0
+     for s:var in [1, 2, 3]
+       total += s:var
+     endfor
+     assert_equal(6, total)
+ 
+     total = 0
+     for var in [1, 2, 3]
+       total += var
+     endfor
+     assert_equal(6, total)
+   END
+ enddef
+ 
  def Test_for_loop_unpack()
    var lines =<< trim END
        var result = []
*** ../vim-8.2.2079/src/version.c       2020-12-02 13:23:30.733664326 +0100
--- src/version.c       2020-12-02 14:13:08.787770425 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2080,
  /**/

-- 
There are 10 kinds of people: Those who understand binary and those who don't.

 /// 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/202012021325.0B2DP2YP4124324%40masaka.moolenaar.net.

Raspunde prin e-mail lui