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.
// 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;
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;
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)
* 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
{
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);
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
" 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
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:')
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1395,
/**/
1394,
/**/
}
// 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);
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,