summaryrefslogtreecommitdiffstats
path: root/src/evalvars.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-09-11 15:14:05 +0100
committerBram Moolenaar <Bram@vim.org>2022-09-11 15:14:05 +0100
commit9510d22463055f56548ff461ccbc54caa1ba1a2f (patch)
tree5c084eccddd0a17e08c4bba2d5fec6d4cc969144 /src/evalvars.c
parentcce82a55b8105560a2ef724999c856966337b48e (diff)
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.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index facafc7dd2..7de785bc4b 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;