To: vim_dev@googlegroups.com Subject: Patch 8.2.1395 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.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. Files: src/vim9compile.c, src/dict.c, src/eval.c, src/evalvars.c, src/proto/evalvars.pro, src/testdir/test_vim9_script.vim, src/testdir/test_vim9_expr.vim *** ../vim-8.2.1394/src/vim9compile.c 2020-08-08 15:10:23.863089456 +0200 --- src/vim9compile.c 2020-08-08 15:39:00.731235903 +0200 *************** *** 5515,5521 **** } // new local variable ! if (type->tt_type == VAR_FUNC && var_check_func_name(name, TRUE)) goto theend; lvar = reserve_local(cctx, var_start, varlen, cmdidx == CMD_const, type); --- 5515,5522 ---- } // new local variable ! 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,5629 **** --- 5625,5636 ---- 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, *** ../vim-8.2.1394/src/dict.c 2020-08-06 16:37:56.728521924 +0200 --- src/dict.c 2020-08-08 15:37:47.591565155 +0200 *************** *** 966,972 **** // 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)) break; if (!valid_varname(hi2->hi_key)) break; --- 966,972 ---- // 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_wrong_func_name(hi2->hi_key, di1 == NULL)) break; if (!valid_varname(hi2->hi_key)) break; *** ../vim-8.2.1394/src/eval.c 2020-08-07 19:28:04.929546817 +0200 --- src/eval.c 2020-08-08 15:38:02.203499382 +0200 *************** *** 1007,1013 **** 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)) || !valid_varname(key); if (len != -1) key[len] = prevval; --- 1007,1013 ---- prevval = 0; // avoid compiler warning wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE && rettv->v_type == VAR_FUNC ! && var_wrong_func_name(key, lp->ll_di == NULL)) || !valid_varname(key); if (len != -1) key[len] = prevval; *** ../vim-8.2.1394/src/evalvars.c 2020-08-05 10:53:15.087273357 +0200 --- src/evalvars.c 2020-08-08 15:38:30.551371723 +0200 *************** *** 2928,2934 **** 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)) return; if (di != NULL) --- 2928,2934 ---- di = find_var_in_scoped_ht(name, TRUE); if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL) ! && var_wrong_func_name(name, di == NULL)) return; if (di != NULL) *************** *** 3114,3120 **** * Return TRUE and give an error if not. */ int ! var_check_func_name( char_u *name, // points to start of variable name int new_var) // TRUE when creating the variable { --- 3114,3120 ---- * Return TRUE and give an error if not. */ int ! var_wrong_func_name( char_u *name, // points to start of variable name int new_var) // TRUE when creating the variable { *** ../vim-8.2.1394/src/proto/evalvars.pro 2020-07-20 21:31:01.268823457 +0200 --- src/proto/evalvars.pro 2020-08-08 15:38:49.535286278 +0200 *************** *** 68,74 **** 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_check_lock(int lock, char_u *name, int use_gettext); int valid_varname(char_u *varname); void reset_v_option_vars(void); --- 68,74 ---- 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_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); *** ../vim-8.2.1394/src/testdir/test_vim9_script.vim 2020-08-08 15:10:23.867089436 +0200 --- src/testdir/test_vim9_script.vim 2020-08-08 15:34:23.288485508 +0200 *************** *** 28,33 **** --- 28,34 ---- 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:') *** ../vim-8.2.1394/src/testdir/test_vim9_expr.vim 2020-08-06 11:23:30.575073657 +0200 --- src/testdir/test_vim9_expr.vim 2020-08-08 15:36:50.191823612 +0200 *************** *** 53,60 **** let RetThat: func = g:atrue ? RetOne : RetTwo assert_equal(function('len'), RetThat) ! let x = FuncOne ! let y = FuncTwo let Z = g:cond ? FuncOne : FuncTwo assert_equal(123, Z(3)) enddef --- 53,60 ---- let RetThat: func = g:atrue ? RetOne : RetTwo assert_equal(function('len'), RetThat) ! let X = FuncOne ! let Y = FuncTwo let Z = g:cond ? FuncOne : FuncTwo assert_equal(123, Z(3)) enddef *************** *** 132,139 **** " missing argument detected even when common type is used call CheckDefFailure([ ! \ 'let x = FuncOne', ! \ 'let y = FuncTwo', \ 'let Z = g:cond ? FuncOne : FuncTwo', \ 'Z()'], 'E119:') endfunc --- 132,139 ---- " missing argument detected even when common type is used call CheckDefFailure([ ! \ 'let X = FuncOne', ! \ 'let Y = FuncTwo', \ 'let Z = g:cond ? FuncOne : FuncTwo', \ 'Z()'], 'E119:') endfunc *** ../vim-8.2.1394/src/version.c 2020-08-08 15:10:23.867089436 +0200 --- src/version.c 2020-08-08 15:32:57.412872741 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1395, /**/ -- Although the scythe isn't pre-eminent among the weapons of war, anyone who has been on the wrong end of, say, a peasants' revolt will know that in skilled hands it is fearsome. -- (Terry Pratchett, Mort) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///