changeset 27690:fae9567b8024 v8.2.4371

patch 8.2.4371: Vim9: can create a script variable from a legacy function Commit: https://github.com/vim/vim/commit/75e27d78f5370e7d2e0898326d9b080937e7b090 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 13 13:56:29 2022 +0000 patch 8.2.4371: Vim9: can create a script variable from a legacy function Problem: Vim9: can create a script variable from a legacy function. Solution: Disallow creating a script variable from a function.
author Bram Moolenaar <Bram@vim.org>
date Sun, 13 Feb 2022 15:00:03 +0100
parents 162c1a47e616
children 8ecc769fa19b
files src/errors.h src/evalvars.c src/testdir/test_vim9_script.vim src/version.c
diffstat 4 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/errors.h
+++ b/src/errors.h
@@ -3234,4 +3234,6 @@ EXTERN char e_function_name_must_start_w
 	INIT(= N_("E1267: Function name must start with a capital: %s"));
 EXTERN char e_cannot_use_s_colon_in_vim9_script_str[]
 	INIT(= N_("E1268: Cannot use s: in Vim9 script: %s"));
+EXTERN char e_cannot_create_vim9_script_variable_in_function_str[]
+	INIT(= N_("E1269: Cannot create a Vim9 script variable in a function: %s"));
 #endif
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -3504,6 +3504,12 @@ set_var_const(
 	    semsg(_(e_cannot_use_str_itself_it_is_imported), name);
 	    goto failed;
 	}
+	if (!in_vim9script())
+	{
+	    semsg(_(e_cannot_create_vim9_script_variable_in_function_str),
+									 name);
+	    goto failed;
+	}
     }
 
     if (dest_tv == NULL)
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -3071,13 +3071,21 @@ def Test_forward_declaration()
   delete('Xforward')
 enddef
 
-def Test_declare_script_in_func()
+def Test_declare_script_var_in_func()
   var lines =<< trim END
       vim9script
       func Declare()
         let s:local = 123
       endfunc
       Declare()
+  END
+  v9.CheckScriptFailure(lines, 'E1269:')
+enddef
+        
+def Test_lock_script_var()
+  var lines =<< trim END
+      vim9script
+      var local = 123
       assert_equal(123, local)
 
       var error: string
--- 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 */
 /**/
+    4371,
+/**/
     4370,
 /**/
     4369,