]> granicus.if.org Git - vim/commitdiff
patch 8.2.2618: Vim9: cannot use a normal list name to store function refs v8.2.2618
authorBram Moolenaar <Bram@vim.org>
Wed, 17 Mar 2021 19:56:38 +0000 (20:56 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 17 Mar 2021 19:56:38 +0000 (20:56 +0100)
Problem:    Vim9: cannot use a normal list name to store function refs.
Solution:   Allow a lower case name if it is indexed.

src/testdir/test_vim9_assign.vim
src/version.c
src/vim9compile.c

index 23c0a89c85d5ee17fc584ae935938cfbb1285537..f71226e1bd94015dda45cd9747bbf7ab8b1876bc 100644 (file)
@@ -72,6 +72,13 @@ def Test_assignment()
   CheckDefFailure(['var lambda = () => "lambda"'], 'E704:')
   CheckScriptFailure(['var x = "x"'], 'E1124:')
 
+  # lower case name is OK for a list
+  var lambdaLines =<< trim END
+      var lambdaList: list<func> = [Test_syntax]
+      lambdaList[0] = () => "lambda"
+  END
+  CheckDefAndScriptSuccess(lambdaLines)
+
   var nr: number = 1234
   CheckDefFailure(['var nr: number = "asdf"'], 'E1012:')
 
index 3bb4eceb749147dd71439b5b3128c6cd07c2566e..6ac96acbda078e3b31356e74a72c7fcdc04d7eb8 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2618,
 /**/
     2617,
 /**/
index 93ded085777c7e2a3a6a08ad5906d231d7b2ecbb..458b4a1a34cee08730b02bd4e26fc6a05baf33f5 100644 (file)
@@ -5832,11 +5832,13 @@ compile_lhs(
            return FAIL;
        }
 
-       // new local variable
+       // Check the name is valid for a funcref.
        if ((lhs->lhs_type->tt_type == VAR_FUNC
                                      || lhs->lhs_type->tt_type == VAR_PARTIAL)
-                                  && var_wrong_func_name(lhs->lhs_name, TRUE))
+               && var_wrong_func_name(lhs->lhs_name, TRUE))
            return FAIL;
+
+       // New local variable.
        lhs->lhs_lvar = reserve_local(cctx, var_start, lhs->lhs_varlen,
                    cmdidx == CMD_final || cmdidx == CMD_const, lhs->lhs_type);
        if (lhs->lhs_lvar == NULL)
@@ -6275,6 +6277,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
                {
                    if ((rhs_type->tt_type == VAR_FUNC
                                || rhs_type->tt_type == VAR_PARTIAL)
+                           && !lhs.lhs_has_index
                            && var_wrong_func_name(lhs.lhs_name, TRUE))
                        goto theend;