From a749a42ed25534c88c636e5ab6603f1f97b857a4 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 12 Feb 2022 19:52:25 +0000 Subject: patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies Problem: Vim9: allowing use of "s:" leads to inconsistencies. Solution: Disallow using "s:" in Vim9 script at the script level. --- src/userfunc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/userfunc.c') diff --git a/src/userfunc.c b/src/userfunc.c index 59415dbd7..4eead2a63 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -3009,6 +3009,18 @@ get_current_funccal(void) return current_funccal; } +/* + * Return TRUE when currently at the script level: + * - not in a function + * - not executing an autocommand + * Note that when an autocommand sources a script the result is FALSE; + */ + int +at_script_level(void) +{ + return current_funccal == NULL && autocmd_match == NULL; +} + /* * Mark all functions of script "sid" as deleted. */ @@ -4205,6 +4217,12 @@ define_function(exarg_T *eap, char_u *name_arg, garray_T *lines_to_free) } else { + if (vim9script && p[0] == 's' && p[1] == ':') + { + semsg(_(e_cannot_use_s_colon_in_vim9_script_str), p); + return NULL; + } + name = save_function_name(&p, &is_global, eap->skip, TFN_NO_AUTOLOAD | TFN_NEW_FUNC, &fudi); paren = (vim_strchr(p, '(') != NULL); -- cgit v1.2.1