# HG changeset patch # User Bram Moolenaar # Date 1640003403 -3600 # Node ID 2b17f87b7bd16d5dd5a5b17f704616e74762fc7b # Parent c4b51a7d535ead6f22ff29453f104fbdda5f9ea2 patch 8.2.3859: Vim9: some code lines not tested Commit: https://github.com/vim/vim/commit/a99fb23842f055c511bfe1b62de7bbd14d5a99c0 Author: Bram Moolenaar Date: Mon Dec 20 12:25:03 2021 +0000 patch 8.2.3859: Vim9: some code lines not tested Problem: Vim9: some code lines not tested. Solution: Add a few specific tests. diff --git a/src/errors.h b/src/errors.h --- a/src/errors.h +++ b/src/errors.h @@ -850,3 +850,5 @@ EXTERN char e_string_list_or_blob_requir INIT(= N_("E1252: String, List or Blob required for argument %d")); EXTERN char e_string_expected_for_argument_nr[] INIT(= N_("E1253: String expected for argument %d")); +EXTERN char e_cannot_use_script_variable_in_for_loop[] + INIT(= N_("E1254: Cannot use script variable in for loop")); diff --git a/src/testdir/test_vim9_cmd.vim b/src/testdir/test_vim9_cmd.vim --- a/src/testdir/test_vim9_cmd.vim +++ b/src/testdir/test_vim9_cmd.vim @@ -1392,6 +1392,10 @@ def Test_lockvar() s:theList[1] = 44 assert_equal([1, 44, 3], s:theList) + if 0 + lockvar whatever + endif + var d = {a: 1, b: 2} d.a = 3 d.b = 4 diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -2963,7 +2963,7 @@ enddef def Test_for_loop_script_var() # cannot use s:var in a :def function - CheckDefFailure(['for s:var in range(3)', 'echo 3'], 'E461:') + CheckDefFailure(['for s:var in range(3)', 'echo 3'], 'E1254:') # can use s:var in Vim9 script, with or without s: var lines =<< trim END diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -750,6 +750,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3859, +/**/ 3858, /**/ 3857, diff --git a/src/vim9compile.c b/src/vim9compile.c --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -8333,7 +8333,6 @@ compile_for(char_u *arg_start, cctx_T *c lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE); } - // Script var is not supported. if (get_var_dest(name, &dest, CMD_for, &opt_flags, &vimvaridx, &type, cctx) == FAIL) goto failed; @@ -8351,6 +8350,13 @@ compile_for(char_u *arg_start, cctx_T *c } else { + // Script var is not supported. + if (STRNCMP(name, "s:", 2) == 0) + { + emsg(_(e_cannot_use_script_variable_in_for_loop)); + goto failed; + } + if (!valid_varname(arg, (int)varlen, FALSE)) goto failed; if (lookup_local(arg, varlen, NULL, cctx) == OK) @@ -8359,12 +8365,6 @@ compile_for(char_u *arg_start, cctx_T *c 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". where.wt_index = var_list ? idx + 1 : 0; where.wt_variable = TRUE;