diff src/evalvars.c @ 23233:657216220293 v8.2.2162

patch 8.2.2162: Vim9: Cannot load or store autoload variables Commit: https://github.com/vim/vim/commit/03290b8444b69c6d7307755770467bc488384e1a Author: Bram Moolenaar <Bram@vim.org> Date: Sat Dec 19 16:30:44 2020 +0100 patch 8.2.2162: Vim9: Cannot load or store autoload variables Problem: Vim9: Cannot load or store autoload variables. Solution: Add ISN_LOADAUTO and ISN_STOREAUTO. (closes https://github.com/vim/vim/issues/7485)
author Bram Moolenaar <Bram@vim.org>
date Sat, 19 Dec 2020 16:45:06 +0100
parents 98548b8fbc98
children a789a688e37d
line wrap: on
line diff
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -3195,8 +3195,10 @@ set_var_const(
 	    goto failed;
 	}
 
-	// Make sure the variable name is valid.
-	if (!valid_varname(varname))
+	// Make sure the variable name is valid.  In Vim9 script an autoload
+	// variable must be prefixed with "g:".
+	if (!valid_varname(varname, !vim9script
+					       || STRNCMP(name, "g:", 2) == 0))
 	    goto failed;
 
 	di = alloc(sizeof(dictitem_T) + STRLEN(varname));
@@ -3349,17 +3351,17 @@ value_check_lock(int lock, char_u *name,
 }
 
 /*
- * Check if a variable name is valid.
+ * Check if a variable name is valid.  When "autoload" is true "#" is allowed.
  * Return FALSE and give an error if not.
  */
     int
-valid_varname(char_u *varname)
+valid_varname(char_u *varname, int autoload)
 {
     char_u *p;
 
     for (p = varname; *p != NUL; ++p)
 	if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p))
-						   && *p != AUTOLOAD_CHAR)
+					 && !(autoload && *p == AUTOLOAD_CHAR))
 	{
 	    semsg(_(e_illvar), varname);
 	    return FALSE;