Hi list.
Calling a vimscript function which has duplicated argument causes
internal error.
----- test.vim -----
function! s:foo(a, a)
endfunction
call s:foo(1, 2)
----- test.vim end -----
$ vim -u NONE -i NONE -S test.vim
will output "E685: Internal error: hash_add()".
Attached patch fixed it to output general error message to command-line
like "E853: Duplicated argument variables: {variable name}" ,
when declaring function. (not when calling function)
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/src/eval.c b/src/eval.c
index 6e8c26f..f236d1f 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -20470,6 +20470,7 @@ ex_function(eap)
char_u *line_arg = NULL;
garray_T newargs;
garray_T newlines;
+ hashtab_T dupcheck_ht;
int varargs = FALSE;
int mustend = FALSE;
int flags = 0;
@@ -20679,6 +20680,7 @@ ex_function(eap)
/*
* Isolate the arguments: "arg1, arg2, ...)"
*/
+ hash_init(&dupcheck_ht);
while (*p != ')')
{
if (p[0] == '.' && p[1] == '.' && p[2] == '.')
@@ -20707,6 +20709,19 @@ ex_function(eap)
arg = vim_strsave(arg);
if (arg == NULL)
goto erret;
+ /* Check duplicated variable name in arguments. */
+ if (HASHITEM_EMPTY(hash_find(&dupcheck_ht, arg)))
+ {
+ char_u *key = vim_strsave(arg);
+ if (key == NULL)
+ goto erret;
+ hash_add(&dupcheck_ht, key);
+ }
+ else
+ {
+ EMSG2(_(e_dupargvar), arg);
+ goto erret;
+ }
((char_u **)(newargs.ga_data))[newargs.ga_len] = arg;
*p = c;
newargs.ga_len++;
diff --git a/src/globals.h b/src/globals.h
index 2c7f257..8125741 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -1541,6 +1541,7 @@ EXTERN char_u e_write[] INIT(= N_("E80: Error while writing"));
EXTERN char_u e_zerocount[] INIT(= N_("Zero count"));
#ifdef FEAT_EVAL
EXTERN char_u e_usingsid[] INIT(= N_("E81: Using <SID> not in a script context"));
+EXTERN char_u e_dupargvar[] INIT(= N_("E853: Duplicated argument variables: %s"));
#endif
#ifdef FEAT_CLIENTSERVER
EXTERN char_u e_invexprmsg[] INIT(= N_("E449: Invalid expression received"));