diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-05-28 21:06:08 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-05-28 21:06:08 +0200 |
commit | d0edaf9dc253e619ccc321ceaac321aee11c1ea5 (patch) | |
tree | 27559339d69ea3bcfaa8cc8e6a87fd6e752c0d4b /src/vim9script.c | |
parent | dc3275a1ac73b6c4d0c9d2e238ea80b477705b6f (diff) | |
download | vim-git-d0edaf9dc253e619ccc321ceaac321aee11c1ea5.tar.gz |
patch 8.2.2897: Vim9: can use reserved words at the script levelv8.2.2897
Problem: Vim9: can use reserved words at the script level.
Solution: Check variable names for reserved words. (closes #8253)
Diffstat (limited to 'src/vim9script.c')
-rw-r--r-- | src/vim9script.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/vim9script.c b/src/vim9script.c index 02c04e2ea..fbb815c28 100644 --- a/src/vim9script.c +++ b/src/vim9script.c @@ -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 |