]> granicus.if.org Git - vim/commitdiff
patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter v8.2.1395
authorBram Moolenaar <Bram@vim.org>
Sat, 8 Aug 2020 13:46:01 +0000 (15:46 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 8 Aug 2020 13:46:01 +0000 (15:46 +0200)
Problem:    Vim9: no error if declaring a funcref with a lower case letter.
Solution:   Check the name after the type is inferred. Fix confusing name.

src/dict.c
src/eval.c
src/evalvars.c
src/proto/evalvars.pro
src/testdir/test_vim9_expr.vim
src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index ad482cddd5934fb493480edb60f1a350871946cf..b381d476dc80ed0dcbe3f2e3b9d28c684cc63b59 100644 (file)
@@ -966,7 +966,7 @@ dict_extend(dict_T *d1, dict_T *d2, char_u *action)
                // Check the key to be valid when adding to any scope.
                if (d1->dv_scope == VAR_DEF_SCOPE
                        && HI2DI(hi2)->di_tv.v_type == VAR_FUNC
-                       && var_check_func_name(hi2->hi_key, di1 == NULL))
+                       && var_wrong_func_name(hi2->hi_key, di1 == NULL))
                    break;
                if (!valid_varname(hi2->hi_key))
                    break;
index c695468cdfc77fbd88a4c0276f2d393d3d64a407..b1fad1dcd5e32e07168cebcef83be69d58cf3ea7 100644 (file)
@@ -1007,7 +1007,7 @@ get_lval(
                    prevval = 0; // avoid compiler warning
                wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE
                               && rettv->v_type == VAR_FUNC
-                              && var_check_func_name(key, lp->ll_di == NULL))
+                              && var_wrong_func_name(key, lp->ll_di == NULL))
                        || !valid_varname(key);
                if (len != -1)
                    key[len] = prevval;
index 869deefc2fe675c041280c88ff00974a2e11a4c4..70afa8444c6c0b88d0d0f102c889de7b2f12f9a9 100644 (file)
@@ -2928,7 +2928,7 @@ set_var_const(
        di = find_var_in_scoped_ht(name, TRUE);
 
     if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL)
-                                     && var_check_func_name(name, di == NULL))
+                                     && var_wrong_func_name(name, di == NULL))
        return;
 
     if (di != NULL)
@@ -3114,7 +3114,7 @@ var_check_fixed(int flags, char_u *name, int use_gettext)
  * Return TRUE and give an error if not.
  */
     int
-var_check_func_name(
+var_wrong_func_name(
     char_u *name,    // points to start of variable name
     int    new_var)  // TRUE when creating the variable
 {
index 43c25287cae97693245b20d85b4e166e2f86ebc6..f304872230ea1a36f5bbf2b2984759a4d087f840 100644 (file)
@@ -68,7 +68,7 @@ void set_var(char_u *name, typval_T *tv, int copy);
 void set_var_const(char_u *name, type_T *type, typval_T *tv, int copy, int flags);
 int var_check_ro(int flags, char_u *name, int use_gettext);
 int var_check_fixed(int flags, char_u *name, int use_gettext);
-int var_check_func_name(char_u *name, int new_var);
+int var_wrong_func_name(char_u *name, int new_var);
 int var_check_lock(int lock, char_u *name, int use_gettext);
 int valid_varname(char_u *varname);
 void reset_v_option_vars(void);
index 746983d14b1c35d8670d6f53f00e321a2c8e5aa5..7e1e16acdd9d40b3dad16df7fe06e5d2f750f421 100644 (file)
@@ -53,8 +53,8 @@ def Test_expr1()
   let RetThat: func = g:atrue ? RetOne : RetTwo
   assert_equal(function('len'), RetThat)
 
-  let x = FuncOne
-  let y = FuncTwo
+  let X = FuncOne
+  let Y = FuncTwo
   let Z = g:cond ? FuncOne : FuncTwo
   assert_equal(123, Z(3))
 enddef
@@ -132,8 +132,8 @@ func Test_expr1_fails()
 
   " missing argument detected even when common type is used
   call CheckDefFailure([
-       \ 'let x = FuncOne',
-       \ 'let y = FuncTwo',
+       \ 'let X = FuncOne',
+       \ 'let Y = FuncTwo',
        \ 'let Z = g:cond ? FuncOne : FuncTwo',
        \ 'Z()'], 'E119:')
 endfunc
index 10706b1d932b60fbb34739cd1402dddee5a6769f..eedce3201b271949294fc47c8aa6b823911ba398 100644 (file)
@@ -28,6 +28,7 @@ def Test_assignment()
   call CheckDefFailure(['let x:string'], 'E1069:')
   call CheckDefFailure(['let x:string = "x"'], 'E1069:')
   call CheckDefFailure(['let a:string = "x"'], 'E1069:')
+  call CheckDefFailure(['let lambda = {-> "lambda"}'], 'E704:')
 
   let nr: number = 1234
   call CheckDefFailure(['let nr: number = "asdf"'], 'E1013:')
index 17ed09b0f713d275efec1ae1c62b0ebf06a94719..870df176600193b43e95471c78561e1675981c47 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1395,
 /**/
     1394,
 /**/
index 04681fee7eaa20c123441c7bd82606354c1a83e5..0664124fe4c123b8d687258b59380b8c56c60dbd 100644 (file)
@@ -5515,7 +5515,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
            }
 
            // new local variable
-           if (type->tt_type == VAR_FUNC && var_check_func_name(name, TRUE))
+           if ((type->tt_type == VAR_FUNC || type->tt_type == VAR_PARTIAL)
+                                           && var_wrong_func_name(name, TRUE))
                goto theend;
            lvar = reserve_local(cctx, var_start, varlen,
                                                    cmdidx == CMD_const, type);
@@ -5624,6 +5625,12 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
                            emsg(_(e_cannot_use_void));
                            goto theend;
                        }
+                       else if ((stacktype->tt_type == VAR_FUNC
+                                   || stacktype->tt_type == VAR_PARTIAL)
+                                           && var_wrong_func_name(name, TRUE))
+                       {
+                           goto theend;
+                       }
                        else
                        {
                            // An empty list or dict has a &t_void member,