0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter

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.
This commit is contained in:
Bram Moolenaar
2020-08-08 15:46:01 +02:00
parent 2dd0a2c39a
commit 98b4f145eb
8 changed files with 20 additions and 10 deletions

View 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. // Check the key to be valid when adding to any scope.
if (d1->dv_scope == VAR_DEF_SCOPE if (d1->dv_scope == VAR_DEF_SCOPE
&& HI2DI(hi2)->di_tv.v_type == VAR_FUNC && 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; break;
if (!valid_varname(hi2->hi_key)) if (!valid_varname(hi2->hi_key))
break; break;

View File

@@ -1007,7 +1007,7 @@ get_lval(
prevval = 0; // avoid compiler warning prevval = 0; // avoid compiler warning
wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE
&& rettv->v_type == VAR_FUNC && 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); || !valid_varname(key);
if (len != -1) if (len != -1)
key[len] = prevval; key[len] = prevval;

View File

@@ -2928,7 +2928,7 @@ set_var_const(
di = find_var_in_scoped_ht(name, TRUE); di = find_var_in_scoped_ht(name, TRUE);
if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL) 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; return;
if (di != NULL) 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. * Return TRUE and give an error if not.
*/ */
int int
var_check_func_name( var_wrong_func_name(
char_u *name, // points to start of variable name char_u *name, // points to start of variable name
int new_var) // TRUE when creating the variable int new_var) // TRUE when creating the variable
{ {

View 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); 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_ro(int flags, char_u *name, int use_gettext);
int var_check_fixed(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 var_check_lock(int lock, char_u *name, int use_gettext);
int valid_varname(char_u *varname); int valid_varname(char_u *varname);
void reset_v_option_vars(void); void reset_v_option_vars(void);

View File

@@ -53,8 +53,8 @@ def Test_expr1()
let RetThat: func = g:atrue ? RetOne : RetTwo let RetThat: func = g:atrue ? RetOne : RetTwo
assert_equal(function('len'), RetThat) assert_equal(function('len'), RetThat)
let x = FuncOne let X = FuncOne
let y = FuncTwo let Y = FuncTwo
let Z = g:cond ? FuncOne : FuncTwo let Z = g:cond ? FuncOne : FuncTwo
assert_equal(123, Z(3)) assert_equal(123, Z(3))
enddef enddef
@@ -132,8 +132,8 @@ func Test_expr1_fails()
" missing argument detected even when common type is used " missing argument detected even when common type is used
call CheckDefFailure([ call CheckDefFailure([
\ 'let x = FuncOne', \ 'let X = FuncOne',
\ 'let y = FuncTwo', \ 'let Y = FuncTwo',
\ 'let Z = g:cond ? FuncOne : FuncTwo', \ 'let Z = g:cond ? FuncOne : FuncTwo',
\ 'Z()'], 'E119:') \ 'Z()'], 'E119:')
endfunc endfunc

View File

@@ -28,6 +28,7 @@ def Test_assignment()
call CheckDefFailure(['let x:string'], 'E1069:') call CheckDefFailure(['let x:string'], 'E1069:')
call CheckDefFailure(['let x:string = "x"'], 'E1069:') call CheckDefFailure(['let x:string = "x"'], 'E1069:')
call CheckDefFailure(['let a:string = "x"'], 'E1069:') call CheckDefFailure(['let a:string = "x"'], 'E1069:')
call CheckDefFailure(['let lambda = {-> "lambda"}'], 'E704:')
let nr: number = 1234 let nr: number = 1234
call CheckDefFailure(['let nr: number = "asdf"'], 'E1013:') call CheckDefFailure(['let nr: number = "asdf"'], 'E1013:')

View File

@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1395,
/**/ /**/
1394, 1394,
/**/ /**/

View File

@@ -5515,7 +5515,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
} }
// new local variable // 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; goto theend;
lvar = reserve_local(cctx, var_start, varlen, lvar = reserve_local(cctx, var_start, varlen,
cmdidx == CMD_const, type); 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)); emsg(_(e_cannot_use_void));
goto theend; goto theend;
} }
else if ((stacktype->tt_type == VAR_FUNC
|| stacktype->tt_type == VAR_PARTIAL)
&& var_wrong_func_name(name, TRUE))
{
goto theend;
}
else else
{ {
// An empty list or dict has a &t_void member, // An empty list or dict has a &t_void member,