Skip to content

Commit

Permalink
patch 8.2.3859: Vim9: some code lines not tested
Browse files Browse the repository at this point in the history
Problem:    Vim9: some code lines not tested.
Solution:   Add a few specific tests.
  • Loading branch information
brammool committed Dec 20, 2021
1 parent 003312b commit a99fb23
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -850,3 +850,5 @@ EXTERN char e_string_list_or_blob_required_for_argument_nr[]
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"));
4 changes: 4 additions & 0 deletions src/testdir/test_vim9_cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/testdir/test_vim9_script.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3859,
/**/
3858,
/**/
Expand Down
14 changes: 7 additions & 7 deletions src/vim9compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8333,7 +8333,6 @@ compile_for(char_u *arg_start, cctx_T *cctx)
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;
Expand All @@ -8351,17 +8350,18 @@ compile_for(char_u *arg_start, cctx_T *cctx)
}
else
{
if (!valid_varname(arg, (int)varlen, FALSE))
goto failed;
if (lookup_local(arg, varlen, NULL, cctx) == OK)
// Script var is not supported.
if (STRNCMP(name, "s:", 2) == 0)
{
semsg(_(e_variable_already_declared), arg);
emsg(_(e_cannot_use_script_variable_in_for_loop));
goto failed;
}

if (STRNCMP(name, "s:", 2) == 0)
if (!valid_varname(arg, (int)varlen, FALSE))
goto failed;
if (lookup_local(arg, varlen, NULL, cctx) == OK)
{
semsg(_(e_cannot_declare_script_variable_in_function), name);
semsg(_(e_variable_already_declared), arg);
goto failed;
}

Expand Down

0 comments on commit a99fb23

Please sign in to comment.