diff src/vim9execute.c @ 21481:279b3415947f v8.2.1291

patch 8.2.1291: Vim9: type of varargs items is not checked Commit: https://github.com/vim/vim/commit/24aa48b7a265c24e18f0f978dfe0255e138e2b90 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 25 16:33:02 2020 +0200 patch 8.2.1291: Vim9: type of varargs items is not checked Problem: Vim9: type of varargs items is not checked. Solution: Check the list item types. (closes https://github.com/vim/vim/issues/6523)
author Bram Moolenaar <Bram@vim.org>
date Sat, 25 Jul 2020 16:45:04 +0200
parents 66386ca8a69f
children 1c4d4aa22b37
line wrap: on
line diff
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -755,9 +755,27 @@ call_def_function(
 	    argc -= vararg_count;
 	if (exe_newlist(vararg_count, &ectx) == FAIL)
 	    goto failed_early;
+
+	// Check the type of the list items.
+	tv = STACK_TV_BOT(-1);
+	if (ufunc->uf_va_type != NULL
+		&& ufunc->uf_va_type->tt_member != &t_any
+		&& tv->vval.v_list != NULL)
+	{
+	    type_T	*expected = ufunc->uf_va_type->tt_member;
+	    listitem_T	*li = tv->vval.v_list->lv_first;
+
+	    for (idx = 0; idx < vararg_count; ++idx)
+	    {
+		if (check_typval_type(expected, &li->li_tv) == FAIL)
+		    goto failed_early;
+		li = li->li_next;
+	    }
+	}
+
 	if (defcount > 0)
 	    // Move varargs list to below missing default arguments.
-	    *STACK_TV_BOT(defcount- 1) = *STACK_TV_BOT(-1);
+	    *STACK_TV_BOT(defcount - 1) = *STACK_TV_BOT(-1);
 	--ectx.ec_stack.ga_len;
     }