]> granicus.if.org Git - vim/commitdiff
patch 8.2.1012: Vim9: cannot declare single character script variables v8.2.1012
authorBram Moolenaar <Bram@vim.org>
Fri, 19 Jun 2020 17:01:43 +0000 (19:01 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 19 Jun 2020 17:01:43 +0000 (19:01 +0200)
Problem:    Vim9: cannot declare single character script variables.
Solution:   Don't see "b:", "s:", etc. as namespace.  Fix item size of
            sn_var_vals.

src/scriptfile.c
src/testdir/test_vim9_script.vim
src/version.c
src/vim9script.c

index 746a3d34449ff59b589bde4993254b0ec19257b0..abfa3b588ec7b9f25081950560d65cb594e02fae 100644 (file)
@@ -1343,7 +1343,7 @@ do_source(
 
            // Allocate the local script variables to use for this script.
            new_script_vars(script_items.ga_len);
-           ga_init2(&si->sn_var_vals, sizeof(typval_T), 10);
+           ga_init2(&si->sn_var_vals, sizeof(svar_T), 10);
            ga_init2(&si->sn_imports, sizeof(imported_T), 10);
            ga_init2(&si->sn_type_list, sizeof(type_T), 10);
 # ifdef FEAT_PROFILE
index 3cfacbb84319ce17a55871330c6e04e68d75c9b6..d1587a2069b89e3c9f597cf211b284aa8ad87d00 100644 (file)
@@ -109,6 +109,41 @@ def Test_assignment()
   call CheckDefFailure(['v:errmsg += 123'], 'E1013:')
 enddef
 
+def Test_vim9_single_char_vars()
+  let lines =<< trim END
+      vim9script
+
+      " single character variable declarations work
+      let a: string
+      let b: number
+      let l: list<any>
+      let s: string
+      let t: number
+      let v: number
+      let w: number
+
+      " script-local variables can be used without s: prefix
+      a = 'script-a'
+      b = 111
+      l = [1, 2, 3]
+      s = 'script-s'
+      t = 222
+      v = 333
+      w = 444
+
+      assert_equal('script-a', a)
+      assert_equal(111, b)
+      assert_equal([1, 2, 3], l)
+      assert_equal('script-s', s)
+      assert_equal(222, t)
+      assert_equal(333, v)
+      assert_equal(444, w)
+  END
+  writefile(lines, 'Xsinglechar')
+  source Xsinglechar
+  delete('Xsinglechar')
+enddef
+
 def Test_assignment_list()
   let list1: list<bool> = [false, true, false]
   let list2: list<number> = [1, 2, 3]
index cc580fb855154ed1113186416235af141ab67fc2..9fc56709ab063f28c2f37c46725901bfe0604b23 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1012,
 /**/
     1011,
 /**/
index 6c4cbc4305b55ff1adad49f0bcb0be9817e8cb4e..30c269af834806b534afb94257490ef6e6efa11c 100644 (file)
@@ -471,7 +471,7 @@ vim9_declare_scriptvar(exarg_T *eap, char_u *arg)
     }
 
     for (p = arg + 1; *p != NUL && eval_isnamec(*p); MB_PTR_ADV(p))
-       if (*p == ':' && p != arg + 1)
+       if (*p == ':' && (VIM_ISWHITE(p[1]) || p != arg + 1))
            break;
 
     if (*p != ':')