Skip to content

Commit

Permalink
patch 8.2.4371: Vim9: can create a script variable from a legacy func…
Browse files Browse the repository at this point in the history
…tion

Problem:    Vim9: can create a script variable from a legacy function.
Solution:   Disallow creating a script variable from a function.
  • Loading branch information
brammool committed Feb 13, 2022
1 parent cf6ad8e commit 75e27d7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/errors.h
Expand Up @@ -3234,4 +3234,6 @@ EXTERN char e_function_name_must_start_with_capital_str[]
INIT(= N_("E1267: Function name must start with a capital: %s"));
EXTERN char e_cannot_use_s_colon_in_vim9_script_str[]
INIT(= N_("E1268: Cannot use s: in Vim9 script: %s"));
EXTERN char e_cannot_create_vim9_script_variable_in_function_str[]
INIT(= N_("E1269: Cannot create a Vim9 script variable in a function: %s"));
#endif
6 changes: 6 additions & 0 deletions src/evalvars.c
Expand Up @@ -3504,6 +3504,12 @@ set_var_const(
semsg(_(e_cannot_use_str_itself_it_is_imported), name);
goto failed;
}
if (!in_vim9script())
{
semsg(_(e_cannot_create_vim9_script_variable_in_function_str),
name);
goto failed;
}
}

if (dest_tv == NULL)
Expand Down
10 changes: 9 additions & 1 deletion src/testdir/test_vim9_script.vim
Expand Up @@ -3071,13 +3071,21 @@ def Test_forward_declaration()
delete('Xforward')
enddef

def Test_declare_script_in_func()
def Test_declare_script_var_in_func()
var lines =<< trim END
vim9script
func Declare()
let s:local = 123
endfunc
Declare()
END
v9.CheckScriptFailure(lines, 'E1269:')
enddef

def Test_lock_script_var()
var lines =<< trim END
vim9script
var local = 123
assert_equal(123, local)

var error: string
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4371,
/**/
4370,
/**/
Expand Down

0 comments on commit 75e27d7

Please sign in to comment.