summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-08-08 15:46:01 +0200
committerBram Moolenaar <Bram@vim.org>2020-08-08 15:46:01 +0200
commit98b4f145eb89405021e23a4a37db51d60a75a1d0 (patch)
tree5d359da0f267a784d3f419e61c36aa47f36d4b2f
parent2dd0a2c39a3b3fbffc94d0676e472c78d02ebdbd (diff)
downloadvim-git-98b4f145eb89405021e23a4a37db51d60a75a1d0.tar.gz
patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letterv8.2.1395
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.
-rw-r--r--src/dict.c2
-rw-r--r--src/eval.c2
-rw-r--r--src/evalvars.c4
-rw-r--r--src/proto/evalvars.pro2
-rw-r--r--src/testdir/test_vim9_expr.vim8
-rw-r--r--src/testdir/test_vim9_script.vim1
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c9
8 files changed, 20 insertions, 10 deletions
diff --git a/src/dict.c b/src/dict.c
index ad482cddd..b381d476d 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -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;
diff --git a/src/eval.c b/src/eval.c
index c695468cd..b1fad1dcd 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -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;
diff --git a/src/evalvars.c b/src/evalvars.c
index 869deefc2..70afa8444 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -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
{
diff --git a/src/proto/evalvars.pro b/src/proto/evalvars.pro
index 43c25287c..f30487223 100644
--- a/src/proto/evalvars.pro
+++ b/src/proto/evalvars.pro
@@ -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);
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 746983d14..7e1e16acd 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -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
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 10706b1d9..eedce3201 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -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:')
diff --git a/src/version.c b/src/version.c
index 17ed09b0f..870df1766 100644
--- 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 */
/**/
+ 1395,
+/**/
1394,
/**/
1393,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 04681fee7..0664124fe 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -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,