To: vim_dev@googlegroups.com Subject: Patch 8.2.4324 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4324 Problem: Vim9: script-local function name can start with "_". Solution: Check for leading capital after "s:". Correct error message. Files: src/userfunc.c, src/errors.h, src/vim9compile.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.4323/src/userfunc.c 2022-02-06 13:08:37.467920903 +0000 --- src/userfunc.c 2022-02-07 21:42:43.154360495 +0000 *************** *** 3884,3898 **** // In Vim9 script a user function is script-local by default, unless it // starts with a lower case character: dict.func(). vim9script = ASCII_ISUPPER(*start) && in_vim9script(); - if (vim9script) - { - char_u *p; - - // SomeScript#func() is a global function. - for (p = start; *p != NUL && *p != '('; ++p) - if (*p == AUTOLOAD_CHAR) - vim9script = FALSE; - } /* * Copy the function name to allocated memory. --- 3884,3889 ---- *************** *** 3904,3910 **** --- 3895,3911 ---- else if (lead > 0 || vim9script) { if (!vim9script) + { + if (in_vim9script() && lead == 2 && !ASCII_ISUPPER(*lv.ll_name)) + { + semsg(_(in_vim9script() + ? e_function_name_must_start_with_capital_str + : e_function_name_must_start_with_capital_or_s_str), + start); + goto theend; + } lead = 3; + } if (vim9script || (lv.ll_exp_name != NULL && eval_fname_sid(lv.ll_exp_name)) || eval_fname_sid(*pp)) *************** *** 3925,3931 **** else if (!(flags & TFN_INT) && (builtin_function(lv.ll_name, len) || (in_vim9script() && *lv.ll_name == '_'))) { ! semsg(_(e_function_name_must_start_with_capital_or_s_str), start); goto theend; } if (!skip && !(flags & TFN_QUIET) && !(flags & TFN_NO_DEREF)) --- 3926,3935 ---- else if (!(flags & TFN_INT) && (builtin_function(lv.ll_name, len) || (in_vim9script() && *lv.ll_name == '_'))) { ! semsg(_(in_vim9script() ! ? e_function_name_must_start_with_capital_str ! : e_function_name_must_start_with_capital_or_s_str), ! start); goto theend; } if (!skip && !(flags & TFN_QUIET) && !(flags & TFN_NO_DEREF)) *** ../vim-8.2.4323/src/errors.h 2022-02-07 13:53:56.376933433 +0000 --- src/errors.h 2022-02-07 21:40:33.878505680 +0000 *************** *** 3228,3230 **** --- 3228,3234 ---- EXTERN char e_critical_error_in_python3_initialization_check_your_installation[] INIT(= N_("E1266: Critical error in python3 initialization, check your python3 installation")); #endif + #ifdef FEAT_EVAL + EXTERN char e_function_name_must_start_with_capital_str[] + INIT(= N_("E1267: Function name must start with a capital: %s")); + #endif *** ../vim-8.2.4323/src/vim9compile.c 2022-02-07 20:30:52.654800521 +0000 --- src/vim9compile.c 2022-02-07 21:49:45.997854206 +0000 *************** *** 888,894 **** return NULL; if (!ASCII_ISUPPER(is_global ? name_start[2] : name_start[0])) { ! semsg(_(e_function_name_must_start_with_capital_or_s_str), name_start); return NULL; } --- 888,894 ---- return NULL; if (!ASCII_ISUPPER(is_global ? name_start[2] : name_start[0])) { ! semsg(_(e_function_name_must_start_with_capital_str), name_start); return NULL; } *** ../vim-8.2.4323/src/testdir/test_vim9_func.vim 2022-02-07 20:30:52.654800521 +0000 --- src/testdir/test_vim9_func.vim 2022-02-07 21:49:19.049887473 +0000 *************** *** 97,103 **** echo 'foo' endfunc END ! v9.CheckScriptFailure(lines, 'E128:') lines =<< trim END vim9script --- 97,103 ---- echo 'foo' endfunc END ! v9.CheckScriptFailure(lines, 'E1267:') lines =<< trim END vim9script *************** *** 105,111 **** echo 'foo' enddef END ! v9.CheckScriptFailure(lines, 'E128:') enddef def Test_autoload_name_mismatch() --- 105,111 ---- echo 'foo' enddef END ! v9.CheckScriptFailure(lines, 'E1267:') enddef def Test_autoload_name_mismatch() *************** *** 685,695 **** def _Inner() echo 'bad' enddef ! Inner() enddef defcompile END ! v9.CheckScriptFailure(lines, 'E128:') lines =<< trim END vim9script --- 685,695 ---- def _Inner() echo 'bad' enddef ! _Inner() enddef defcompile END ! v9.CheckScriptFailure(lines, 'E1267:') lines =<< trim END vim9script *************** *** 697,707 **** def g:inner() echo 'bad' enddef ! Inner() enddef defcompile END ! v9.CheckScriptFailure(lines, 'E128:') # nested function inside conditional lines =<< trim END --- 697,723 ---- def g:inner() echo 'bad' enddef ! g:inner() enddef defcompile END ! v9.CheckScriptFailure(lines, 'E1267:') ! ! lines =<< trim END ! vim9script ! def g:_Func() ! echo 'bad' ! enddef ! END ! v9.CheckScriptFailure(lines, 'E1267:') ! ! lines =<< trim END ! vim9script ! def s:_Func() ! echo 'bad' ! enddef ! END ! v9.CheckScriptFailure(lines, 'E1267:') # nested function inside conditional lines =<< trim END *************** *** 2772,2778 **** lines =<< trim END vim9script ! def s:func() range(10) ->mapnew((_, _) => ({ key: range(10)->mapnew((_, _) => { --- 2788,2794 ---- lines =<< trim END vim9script ! def s:Func() range(10) ->mapnew((_, _) => ({ key: range(10)->mapnew((_, _) => { *** ../vim-8.2.4323/src/version.c 2022-02-07 20:30:52.654800521 +0000 --- src/version.c 2022-02-07 21:34:54.054849563 +0000 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4324, /**/ -- Q: What is the difference between open-source and commercial software? A: If you have a problem with commercial software you can call a phone number and they will tell you it might be solved in a future version. For open-source software there isn't a phone number to call, but you get the solution within a day. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///