]> granicus.if.org Git - vim/commitdiff
patch 8.2.1387: Vim9: cannot assign to single letter variable with type v8.2.1387
authorBram Moolenaar <Bram@vim.org>
Fri, 7 Aug 2020 17:28:08 +0000 (19:28 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 7 Aug 2020 17:28:08 +0000 (19:28 +0200)
Problem:    Vim9: cannot assign to single letter variable with type.
Solution:   Exclude the colon from the variable name. (closes #6647)

src/eval.c
src/testdir/test_vim9_script.vim
src/version.c

index 877b3bc0ffcd8ace3ce0ce4c916ba8c973c7c2e0..c695468cdfc77fbd88a4c0276f2d393d3d64a407 100644 (file)
@@ -820,14 +820,23 @@ get_lval(
     {
        lp->ll_name = name;
 
-       if (in_vim9script() && *p == ':')
+       if (in_vim9script())
        {
-           scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
-           char_u       *tp = skipwhite(p + 1);
+           // "a: type" is declaring variable "a" with a type, not "a:".
+           if (p == name + 2 && p[-1] == ':')
+           {
+               --p;
+               lp->ll_name_end = p;
+           }
+           if (*p == ':')
+           {
+               scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
+               char_u   *tp = skipwhite(p + 1);
 
-           // parse the type after the name
-           lp->ll_type = parse_type(&tp, &si->sn_type_list);
-           lp->ll_name_end = tp;
+               // parse the type after the name
+               lp->ll_type = parse_type(&tp, &si->sn_type_list);
+               lp->ll_name_end = tp;
+           }
        }
     }
 
index e5d5e872d86732d473ddae87b6c07c27442b7797..ba18af09e3450dbacc05450034aec1a2b8c46a00 100644 (file)
@@ -449,6 +449,17 @@ def Test_assignment_vim9script()
       @+ = 'plus'
       assert_equal('plus', @+)
     endif
+
+    let a: number = 123
+    assert_equal(123, a)
+    let s: string = 'yes'
+    assert_equal('yes', s)
+    let b: number = 42
+    assert_equal(42, b)
+    let w: number = 43
+    assert_equal(43, w)
+    let t: number = 44
+    assert_equal(44, t)
   END
   CheckScriptSuccess(lines)
 enddef
index e251ba865b1ddeb620f00e86081f095a0a4eeb0d..11b686255b8ae2f2623740023ae723f4aafcf840 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1387,
 /**/
     1386,
 /**/