mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2897: Vim9: can use reserved words at the script level
Problem: Vim9: can use reserved words at the script level. Solution: Check variable names for reserved words. (closes #8253)
This commit is contained in:
@@ -709,10 +709,10 @@ vim9_declare_scriptvar(exarg_T *eap, char_u *arg)
|
||||
}
|
||||
name = vim_strnsave(arg, p - arg);
|
||||
|
||||
// parse type
|
||||
// parse type, check for reserved name
|
||||
p = skipwhite(p + 1);
|
||||
type = parse_type(&p, &si->sn_type_list, TRUE);
|
||||
if (type == NULL)
|
||||
if (type == NULL || check_reserved_name(name) == FAIL)
|
||||
{
|
||||
vim_free(name);
|
||||
return p;
|
||||
@@ -974,4 +974,26 @@ check_script_var_type(
|
||||
return OK; // not really
|
||||
}
|
||||
|
||||
// words that cannot be used as a variable
|
||||
static char *reserved[] = {
|
||||
"true",
|
||||
"false",
|
||||
"null",
|
||||
NULL
|
||||
};
|
||||
|
||||
int
|
||||
check_reserved_name(char_u *name)
|
||||
{
|
||||
int idx;
|
||||
|
||||
for (idx = 0; reserved[idx] != NULL; ++idx)
|
||||
if (STRCMP(reserved[idx], name) == 0)
|
||||
{
|
||||
semsg(_(e_cannot_use_reserved_name), name);
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif // FEAT_EVAL
|
||||
|
Reference in New Issue
Block a user