changeset 27291:0f0fa4d12303 v8.2.4174

patch 8.2.4174: Vim9: can use an autoload name in normal script Commit: https://github.com/vim/vim/commit/19e69a63302f7f8972cee723bf0f3fc176825583 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 21 20:37:05 2022 +0000 patch 8.2.4174: Vim9: can use an autoload name in normal script Problem: Vim9: can use an autoload name in normal script. Solution: Disallow using an autoload name.
author Bram Moolenaar <Bram@vim.org>
date Fri, 21 Jan 2022 21:45:03 +0100
parents b1f18b4277c4
children ef412ec5bfdf
files src/errors.h src/testdir/test_vim9_import.vim src/userfunc.c src/version.c
diffstat 4 files changed, 22 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/errors.h
+++ b/src/errors.h
@@ -3209,7 +3209,8 @@ EXTERN char e_cannot_import_dot_vim_with
 	INIT(= N_("E1261: Cannot import .vim without using \"as\""));
 EXTERN char e_cannot_import_same_script_twice_str[]
 	INIT(= N_("E1262: Cannot import the same script twice: %s"));
-// E1263 unused
+EXTERN char e_using_autoload_name_in_non_autoload_script_str[]
+	INIT(= N_("E1263: Using autoload name in a non-autoload script: %s"));
 EXTERN char e_autoload_import_cannot_use_absolute_or_relative_path[]
 	INIT(= N_("E1264: Autoload import cannot use absolute or relative path: %s"));
 EXTERN char e_cannot_use_partial_here[]
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -1622,6 +1622,18 @@ def Test_autoload_missing_function_name(
   delete('Xdir', 'rf')
 enddef
 
+def Test_autoload_name_wring()
+  var lines =<< trim END
+     vim9script
+     def Xscriptname#Func()
+     enddef
+  END
+  writefile(lines, 'Xscriptname.vim')
+  CheckScriptFailure(lines, 'E1263:')
+
+  delete('Xscriptname')
+enddef
+
 def Test_import_autoload_postponed()
   mkdir('Xdir/autoload', 'p')
   var save_rtp = &rtp
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -4495,6 +4495,12 @@ define_function(exarg_T *eap, char_u *na
 		    }
 		}
 	    }
+	    else if (vim9script && vim_strchr(name, AUTOLOAD_CHAR) != NULL)
+	    {
+		semsg(_(e_using_autoload_name_in_non_autoload_script_str),
+									 name);
+		goto erret;
+	    }
 	}
 	if (var_conflict)
 	{
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4174,
+/**/
     4173,
 /**/
     4172,