comparison 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
comparison
equal deleted inserted replaced
23232:adecb0541bb3 23233:657216220293
3193 { 3193 {
3194 semsg(_(e_illvar), name); 3194 semsg(_(e_illvar), name);
3195 goto failed; 3195 goto failed;
3196 } 3196 }
3197 3197
3198 // Make sure the variable name is valid. 3198 // Make sure the variable name is valid. In Vim9 script an autoload
3199 if (!valid_varname(varname)) 3199 // variable must be prefixed with "g:".
3200 if (!valid_varname(varname, !vim9script
3201 || STRNCMP(name, "g:", 2) == 0))
3200 goto failed; 3202 goto failed;
3201 3203
3202 di = alloc(sizeof(dictitem_T) + STRLEN(varname)); 3204 di = alloc(sizeof(dictitem_T) + STRLEN(varname));
3203 if (di == NULL) 3205 if (di == NULL)
3204 goto failed; 3206 goto failed;
3347 } 3349 }
3348 return FALSE; 3350 return FALSE;
3349 } 3351 }
3350 3352
3351 /* 3353 /*
3352 * Check if a variable name is valid. 3354 * Check if a variable name is valid. When "autoload" is true "#" is allowed.
3353 * Return FALSE and give an error if not. 3355 * Return FALSE and give an error if not.
3354 */ 3356 */
3355 int 3357 int
3356 valid_varname(char_u *varname) 3358 valid_varname(char_u *varname, int autoload)
3357 { 3359 {
3358 char_u *p; 3360 char_u *p;
3359 3361
3360 for (p = varname; *p != NUL; ++p) 3362 for (p = varname; *p != NUL; ++p)
3361 if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p)) 3363 if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p))
3362 && *p != AUTOLOAD_CHAR) 3364 && !(autoload && *p == AUTOLOAD_CHAR))
3363 { 3365 {
3364 semsg(_(e_illvar), varname); 3366 semsg(_(e_illvar), varname);
3365 return FALSE; 3367 return FALSE;
3366 } 3368 }
3367 return TRUE; 3369 return TRUE;