0
0
mirror of https://github.com/vim/vim.git synced 2025-09-28 04:24:06 -04:00

patch 9.0.0444: trying to declare g:variable gives confusing error

Problem:    Trying to declare g:variable gives confusing error.
Solution:   Give a better error message. (closes #11108)
This commit is contained in:
Bram Moolenaar
2022-09-11 15:14:05 +01:00
parent cce82a55b8
commit 9510d22463
9 changed files with 51 additions and 20 deletions

View File

@@ -602,6 +602,18 @@ list_script_vars(int *first)
"s:", FALSE, 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 "{".
@@ -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;