From 0e1574c4069ded47c170fcd7a47a0df66693a5f4 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Thu, 3 Mar 2022 17:05:35 +0000 Subject: patch 8.2.4500: Vim9: can declare a global variable on the command line Problem: Vim9: can declare a global variable on the command line. Solution: Disallow declaring a variable on the command line. (closes #9881) --- src/evalvars.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/evalvars.c') diff --git a/src/evalvars.c b/src/evalvars.c index eb69d3e20..260c297b0 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -759,6 +759,11 @@ ex_var(exarg_T *eap) semsg(_(e_str_cannot_be_used_in_legacy_vim_script), ":var"); return; } + if (current_sctx.sc_sid == 0) + { + emsg(_(e_cannot_declare_variable_on_command_line)); + return; + } ex_let(eap); } @@ -3440,7 +3445,7 @@ set_var_const( if (in_vim9script() && is_export && SCRIPT_ID_VALID(current_sctx.sc_sid) && (si = SCRIPT_ITEM(current_sctx.sc_sid)) - ->sn_autoload_prefix != NULL) + ->sn_autoload_prefix != NULL) { // In a vim9 autoload script an exported variable is put in the // global namespace with the autoload prefix. -- cgit v1.2.1