Mercurial > vim
diff src/vim9script.c @ 24717:bf8feac8a89a v8.2.2897
patch 8.2.2897: Vim9: can use reserved words at the script level
Commit: https://github.com/vim/vim/commit/d0edaf9dc253e619ccc321ceaac321aee11c1ea5
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 28 21:06:08 2021 +0200
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 https://github.com/vim/vim/issues/8253)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 28 May 2021 21:15:03 +0200 |
parents | 9c404d78d767 |
children | b6ac4ed5e2d2 |
line wrap: on
line diff
--- a/src/vim9script.c +++ b/src/vim9script.c @@ -709,10 +709,10 @@ vim9_declare_scriptvar(exarg_T *eap, cha } 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