Patch 8.2.2080

4 views
Skip to first unread message

Bram Moolenaar

unread,
Dec 2, 2020, 8:25:12 AM12/2/20
to vim...@googlegroups.com

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 -- Br...@Moolenaar.net -- 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 ///
Reply all
Reply to author
Forward
0 new messages