diff src/userfunc.c @ 27595:d504745607bc v8.2.4324

patch 8.2.4324: Vim9: script-local function name can start with "_" Commit: https://github.com/vim/vim/commit/3787f26c2ed33732a36f26ebe46faeebfe0151af Author: Bram Moolenaar <Bram@vim.org> Date: Mon Feb 7 21:54:01 2022 +0000 patch 8.2.4324: Vim9: script-local function name can start with "_" Problem: Vim9: script-local function name can start with "_". Solution: Check for leading capital after "s:". Correct error message.
author Bram Moolenaar <Bram@vim.org>
date Mon, 07 Feb 2022 23:00:03 +0100
parents a54064e14114
children e311a80f8cbe
line wrap: on
line diff
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -3884,15 +3884,6 @@ trans_function_name(
     // In Vim9 script a user function is script-local by default, unless it
     // starts with a lower case character: dict.func().
     vim9script = ASCII_ISUPPER(*start) && in_vim9script();
-    if (vim9script)
-    {
-	char_u *p;
-
-	// SomeScript#func() is a global function.
-	for (p = start; *p != NUL && *p != '('; ++p)
-	    if (*p == AUTOLOAD_CHAR)
-		vim9script = FALSE;
-    }
 
     /*
      * Copy the function name to allocated memory.
@@ -3904,7 +3895,17 @@ trans_function_name(
     else if (lead > 0 || vim9script)
     {
 	if (!vim9script)
+	{
+	    if (in_vim9script() && lead == 2 && !ASCII_ISUPPER(*lv.ll_name))
+	    {
+		semsg(_(in_vim9script()
+			   ? e_function_name_must_start_with_capital_str
+			   : e_function_name_must_start_with_capital_or_s_str),
+									start);
+		goto theend;
+	    }
 	    lead = 3;
+	}
 	if (vim9script || (lv.ll_exp_name != NULL
 					     && eval_fname_sid(lv.ll_exp_name))
 						       || eval_fname_sid(*pp))
@@ -3925,7 +3926,10 @@ trans_function_name(
     else if (!(flags & TFN_INT) && (builtin_function(lv.ll_name, len)
 				   || (in_vim9script() && *lv.ll_name == '_')))
     {
-	semsg(_(e_function_name_must_start_with_capital_or_s_str), start);
+	semsg(_(in_vim9script()
+			   ? e_function_name_must_start_with_capital_str
+			   : e_function_name_must_start_with_capital_or_s_str),
+									start);
 	goto theend;
     }
     if (!skip && !(flags & TFN_QUIET) && !(flags & TFN_NO_DEREF))