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)
diff --git a/src/evalvars.c b/src/evalvars.c
index eb69d3e..260c297 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -759,6 +759,11 @@
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 @@
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.