changeset 26992:8433e5c87651 v8.2.4025

patch 8.2.4025: error for import not ending in .vim does not work for .vimrc Commit: https://github.com/vim/vim/commit/834d41853e12b9022f60b08c32480928c2a9e48f Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 7 13:38:24 2022 +0000 patch 8.2.4025: error for import not ending in .vim does not work for .vimrc Problem: Error for import not ending in .vim does not work for .vimrc. Solution: Check that .vim is the end. (closes https://github.com/vim/vim/issues/9484)
author Bram Moolenaar <Bram@vim.org>
date Fri, 07 Jan 2022 14:45:04 +0100
parents f57ec31a2cef
children 9a8859c832f0
files src/errors.h src/testdir/test_vim9_script.vim src/version.c src/vim9script.c
diffstat 4 files changed, 42 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/errors.h
+++ b/src/errors.h
@@ -2881,11 +2881,13 @@ EXTERN char e_cmd_mapping_must_end_with_
 	INIT(= N_("E1255: <Cmd> mapping must end with <CR>"));
 EXTERN char e_string_or_function_required_for_argument_nr[]
 	INIT(= N_("E1256: String or function required for argument %d"));
-EXTERN char e_imported_script_must_end_in_dot_vim_str[]
-	INIT(= N_("E1257: Imported script must end in .vim: %s"));
+EXTERN char e_imported_script_must_use_as_or_end_in_dot_vim_str[]
+	INIT(= N_("E1257: Imported script must use \"as\" or end in .vim: %s"));
 EXTERN char e_no_dot_after_imported_name_str[]
 	INIT(= N_("E1258: No '.' after imported name: %s"));
 EXTERN char e_missing_name_after_imported_name_str[]
 	INIT(= N_("E1259: Missing name after imported name: %s"));
 EXTERN char e_cannot_unlet_imported_item_str[]
 	INIT(= N_("E1260: Cannot unlet an imported item: %s"));
+EXTERN char e_cannot_import_dot_vim_without_using_as[]
+	INIT(= N_("E1261: Cannot import .vim without using \"as\""));
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1527,7 +1527,7 @@ def Test_import_funcref()
   delete('Xlib.vim')
 enddef
 
-def Test_import_star_fails()
+def Test_import_fails()
   writefile([], 'Xfoo.vim')
   var lines =<< trim END
       import './Xfoo.vim' as foo
@@ -1572,7 +1572,34 @@ def Test_import_star_fails()
       That()
   END
   CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use That itself'])
-  delete('Xthat.vim')
+ 
+  mkdir('Xdir')
+
+  writefile(['vim9script'], 'Xdir/.vim')
+  lines =<< trim END
+      vim9script
+      import './Xdir/.vim'
+  END
+  CheckScriptFailure(lines, 'E1261: Cannot import .vim without using "as"')
+  lines =<< trim END
+      vim9script
+      import './Xdir/.vim' as vim
+  END
+  CheckScriptSuccess(lines)
+
+  writefile(['vim9script'], 'Xdir/.vimrc')
+  lines =<< trim END
+      vim9script
+      import './Xdir/.vimrc'
+  END
+  CheckScriptFailure(lines, 'E1257: Imported script must use "as" or end in .vim')
+  lines =<< trim END
+      vim9script
+      import './Xdir/.vimrc' as vimrc
+  END
+  CheckScriptSuccess(lines)
+
+  delete('Xdir', 'rf')
 enddef
 
 func g:Trigger()
--- 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 */
 /**/
+    4025,
+/**/
     4024,
 /**/
     4023,
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -474,10 +474,14 @@ handle_import(
 	    semsg(_(e_trailing_characters_str), expr_end);
 	    goto erret;
 	}
-
-	if (end == NULL)
+	if (end == NULL || end[4] != NUL)
 	{
-	    semsg(_(e_imported_script_must_end_in_dot_vim_str), p);
+	    semsg(_(e_imported_script_must_use_as_or_end_in_dot_vim_str), p);
+	    goto erret;
+	}
+	if (end == p)
+	{
+	    semsg(_(e_cannot_import_dot_vim_without_using_as), p);
 	    goto erret;
 	}
 	as_name = vim_strnsave(p, end - p);