diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-09-11 15:14:05 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-09-11 15:14:05 +0100 |
commit | 9510d22463055f56548ff461ccbc54caa1ba1a2f (patch) | |
tree | 5c084eccddd0a17e08c4bba2d5fec6d4cc969144 /src/evalvars.c | |
parent | cce82a55b8105560a2ef724999c856966337b48e (diff) | |
download | vim-git-9510d22463055f56548ff461ccbc54caa1ba1a2f.tar.gz |
patch 9.0.0444: trying to declare g:variable gives confusing errorv9.0.0444
Problem: Trying to declare g:variable gives confusing error.
Solution: Give a better error message. (closes #11108)
Diffstat (limited to 'src/evalvars.c')
-rw-r--r-- | src/evalvars.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index facafc7dd..7de785bc4 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -603,6 +603,18 @@ list_script_vars(int *first) } /* + * Return TRUE if "name" starts with "g:", "w:", "t:" or "b:". + * But only when an identifier character follows. + */ + int +is_scoped_variable(char_u *name) +{ + return vim_strchr((char_u *)"gwbt", name[0]) != NULL + && name[1] == ':' + && eval_isnamec(name[2]); +} + +/* * Evaluate one Vim expression {expr} in string "p" and append the * resulting string to "gap". "p" points to the opening "{". * When "evaluate" is FALSE only skip over the expression. @@ -3679,8 +3691,7 @@ set_var_const( vim9_declare_error(name); goto failed; } - if ((flags & ASSIGN_FOR_LOOP) && name[1] == ':' - && vim_strchr((char_u *)"gwbt", name[0]) != NULL) + if ((flags & ASSIGN_FOR_LOOP) && is_scoped_variable(name)) // Do not make g:var, w:var, b:var or t:var final. flags &= ~ASSIGN_FINAL; |