changeset 20846:709379ab5110 v8.2.0975

patch 8.2.0975: Vim9: script variable does not accept optional s: prefix Commit: https://github.com/vim/vim/commit/984dddbef421eda6b8ad60936f380c5f00aebb96 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 14 12:50:24 2020 +0200 patch 8.2.0975: Vim9: script variable does not accept optional s: prefix Problem: Vim9: script variable does not accept optional s: prefix. Solution: Adjust the accepted syntax.
author Bram Moolenaar <Bram@vim.org>
date Sun, 14 Jun 2020 13:00:04 +0200
parents 67df55152c33
children 4e1017c5fbb5
files src/testdir/test_vim9_script.vim src/version.c src/vim9script.c
diffstat 3 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1822,13 +1822,24 @@ def Test_let_declaration()
     g:var_uninit = var
     var = 'text'
     g:var_test = var
+    " prefixing s: is optional
+    s:var = 'prefixed'
+    g:var_prefixed = s:var
+
+    let s:other: number
+    other = 1234
+    g:other_var = other
   END
   CheckScriptSuccess(lines)
   assert_equal('', g:var_uninit)
   assert_equal('text', g:var_test)
+  assert_equal('prefixed', g:var_prefixed)
+  assert_equal(1234, g:other_var)
 
   unlet g:var_uninit
   unlet g:var_test
+  unlet g:var_prefixed
+  unlet g:other_var
 enddef
 
 def Test_let_type_check()
@@ -1838,6 +1849,12 @@ def Test_let_type_check()
     var = 1234
   END
   CheckScriptFailure(lines, 'E1013:')
+
+  lines =<< trim END
+    vim9script
+    let var:string
+  END
+  CheckScriptFailure(lines, 'E1069:')
 enddef
 
 def Test_forward_declaration()
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    975,
+/**/
     974,
 /**/
     973,
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -462,15 +462,20 @@ vim9_declare_scriptvar(exarg_T *eap, cha
 	return arg + STRLEN(arg);
     }
 
-    for (p = arg + 1; *p != NUL && *p != ':' && eval_isnamec(*p);
-								 MB_PTR_ADV(p))
-	;
+    for (p = arg + 1; *p != NUL && eval_isnamec(*p); MB_PTR_ADV(p))
+	if (*p == ':' && p != arg + 1)
+	    break;
 
     if (*p != ':')
     {
 	emsg(_(e_type_req));
 	return arg + STRLEN(arg);
     }
+    if (!VIM_ISWHITE(p[1]))
+    {
+	semsg(_(e_white_after), ":");
+	return arg + STRLEN(arg);
+    }
     name = vim_strnsave(arg, p - arg);
 
     // parse type