Patch 8.2.4460
Problem: Vim9: wrong error for defining dict function.
Solution: Explicitly check for trying to define a dict function.
(closes 9827)
Files: src/errors.h, src/userfunc.c, src/vim9compile.c,
src/testdir/test_vim9_func.vim
*** ../vim-8.2.4459/src/errors.h 2022-02-17 14:41:58.937322107 +0000
--- src/errors.h 2022-02-23 21:30:27.441901784 +0000
***************
*** 3010,3016 ****
INIT(= N_("E1180: Variable arguments type must be a list: %s"));
EXTERN char e_cannot_use_underscore_here[]
INIT(= N_("E1181: Cannot use an underscore here"));
! // E1182 unused
EXTERN char e_cannot_use_range_with_assignment_operator_str[]
INIT(= N_("E1183: Cannot use a range with an assignment operator: %s"));
#endif
--- 3010,3017 ----
INIT(= N_("E1180: Variable arguments type must be a list: %s"));
EXTERN char e_cannot_use_underscore_here[]
INIT(= N_("E1181: Cannot use an underscore here"));
! EXTERN char e_cannot_define_dict_func_in_vim9_script_str[]
! INIT(= N_("E1182: Cannot define a dict function in Vim9 script: %s"));
EXTERN char e_cannot_use_range_with_assignment_operator_str[]
INIT(= N_("E1183: Cannot use a range with an assignment operator: %s"));
#endif
*** ../vim-8.2.4459/src/userfunc.c 2022-02-21 13:13:44.919693176 +0000
--- src/userfunc.c 2022-02-23 21:46:31.146696661 +0000
***************
*** 4268,4277 ****
}
else
{
! if (vim9script && p[0] == 's' && p[1] == ':')
{
! semsg(_(e_cannot_use_s_colon_in_vim9_script_str), p);
! return NULL;
}
name = save_function_name(&p, &is_global, eap->skip,
--- 4268,4288 ----
}
else
{
! if (vim9script)
{
! if (p[0] == 's' && p[1] == ':')
! {
! semsg(_(e_cannot_use_s_colon_in_vim9_script_str), p);
! return NULL;
! }
! p = to_name_end(p, TRUE);
! if (*skipwhite(p) == '.' && vim_strchr(p, '(') != NULL)
! {
! semsg(_(e_cannot_define_dict_func_in_vim9_script_str),
! eap->arg);
! return NULL;
! }
! p = eap->arg;
}
name = save_function_name(&p, &is_global, eap->skip,
*** ../vim-8.2.4459/src/vim9compile.c 2022-02-22 20:42:50.382992530 +0000
--- src/vim9compile.c 2022-02-23 21:56:58.841773049 +0000
***************
*** 831,837 ****
{
if (!ends_excmd2(name_start, name_end))
{
! semsg(_(e_invalid_command_str), eap->cmd);
return NULL;
}
--- 831,841 ----
{
if (!ends_excmd2(name_start, name_end))
{
! if (*skipwhite(name_end) == '.')
! semsg(_(e_cannot_define_dict_func_in_vim9_script_str),
! eap->cmd);
! else
! semsg(_(e_invalid_command_str), eap->cmd);
return NULL;
}
*** ../vim-8.2.4459/src/testdir/test_vim9_func.vim 2022-02-20 15:52:24.388395078 +0000
--- src/testdir/test_vim9_func.vim 2022-02-23 22:03:19.259723579 +0000
***************
*** 106,111 ****
--- 106,168 ----
enddef
END
v9.CheckScriptFailure(lines, 'E1267:')
+
+ lines =<< trim END
+ vim9script
+ var Object = {}
+ function Object.Method()
+ endfunction
+ END
+ v9.CheckScriptFailure(lines, 'E1182:')
+
+ lines =<< trim END
+ vim9script
+ var Object = {}
+ def Object.Method()
+ enddef
+ END
+ v9.CheckScriptFailure(lines, 'E1182:')
+
+ lines =<< trim END
+ vim9script
+ g:Object = {}
+ function g:Object.Method()
+ endfunction
+ END
+ v9.CheckScriptFailure(lines, 'E1182:')
+
+ lines =<< trim END
+ let s:Object = {}
+ def Define()
+ function s:Object.Method()
+ endfunction
+ enddef
+ defcompile
+ END
+ v9.CheckScriptFailure(lines, 'E1182:')
+ delfunc g:Define
+
+ lines =<< trim END
+ let s:Object = {}
+ def Define()
+ def Object.Method()
+ enddef
+ enddef
+ defcompile
+ END
+ v9.CheckScriptFailure(lines, 'E1182:')
+ delfunc g:Define
+
+ lines =<< trim END
+ let g:Object = {}
+ def Define()
+ function g:Object.Method()
+ endfunction
+ enddef
+ defcompile
+ END
+ v9.CheckScriptFailure(lines, 'E1182:')
+ delfunc g:Define
enddef
def Test_autoload_name_mismatch()
*** ../vim-8.2.4459/src/version.c 2022-02-23 21:03:28.913442583 +0000
--- src/version.c 2022-02-23 21:31:25.470045452 +0000
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 4460,
/**/
--
I AM THANKFUL...
...for a lawn that needs mowing, windows that need cleaning
and gutters that need fixing because it means I have a home.
/// Bram Moolenaar -- Br...@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 ///