diff src/popupwin.c @ 25384:e8e2c4d33b9b v8.2.3229

patch 8.2.3229: Vim9: runtime and compile time type checks are not the same Commit: https://github.com/vim/vim/commit/4490ec4e839e45a2e6923c265c7e9e64c240b805 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Tue Jul 27 22:00:44 2021 +0200 patch 8.2.3229: Vim9: runtime and compile time type checks are not the same Problem: Vim9: runtime and compile time type checks are not the same. Solution: Add more runtime type checks for builtin functions. (Yegappan Lakshmanan, closes #8646)
author Bram Moolenaar <Bram@vim.org>
date Tue, 27 Jul 2021 22:15:06 +0200
parents 1ffa8eb30353
children 7cb1597067e0
line wrap: on
line diff
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -1851,6 +1851,11 @@ popup_create(typval_T *argvars, typval_T
     int		nr;
     int		i;
 
+    if (in_vim9script()
+	    && (check_for_string_or_number_or_list_arg(argvars, 0) == FAIL
+		|| check_for_dict_arg(argvars, 1) == FAIL))
+	return NULL;
+
     if (argvars != NULL)
     {
 	// Check that arguments look OK.
@@ -2141,6 +2146,9 @@ f_popup_clear(typval_T *argvars, typval_
 {
     int force = FALSE;
 
+    if (in_vim9script() && check_for_opt_bool_arg(argvars, 0) == FAIL)
+	return;
+
     if (argvars[0].v_type != VAR_UNKNOWN)
 	force = (int)tv_get_bool(&argvars[0]);
     close_all_popups(force);
@@ -2558,9 +2566,14 @@ popup_hide(win_T *wp)
     void
 f_popup_hide(typval_T *argvars, typval_T *rettv UNUSED)
 {
-    int		id = (int)tv_get_number(argvars);
-    win_T	*wp = find_popup_win(id);
-
+    int		id;
+    win_T	*wp;
+
+    if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
+	return;
+
+    id = (int)tv_get_number(argvars);
+    wp = find_popup_win(id);
     if (wp != NULL)
 	popup_hide(wp);
 }
@@ -2582,9 +2595,14 @@ popup_show(win_T *wp)
     void
 f_popup_show(typval_T *argvars, typval_T *rettv UNUSED)
 {
-    int		id = (int)tv_get_number(argvars);
-    win_T	*wp = find_popup_win(id);
-
+    int		id;
+    win_T	*wp;
+
+    if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
+	return;
+
+    id = (int)tv_get_number(argvars);
+    wp = find_popup_win(id);
     if (wp != NULL)
     {
 	popup_show(wp);
@@ -2824,13 +2842,18 @@ f_popup_setoptions(typval_T *argvars, ty
 f_popup_getpos(typval_T *argvars, typval_T *rettv)
 {
     dict_T	*dict;
-    int		id = (int)tv_get_number(argvars);
-    win_T	*wp = find_popup_win(id);
+    int		id;
+    win_T	*wp;
     int		top_extra;
     int		left_extra;
 
     if (rettv_dict_alloc(rettv) == OK)
     {
+	if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
+	    return;
+
+	id = (int)tv_get_number(argvars);
+	wp = find_popup_win(id);
 	if (wp == NULL)
 	    return;  // invalid {id}
 	top_extra = popup_top_extra(wp);
@@ -2886,10 +2909,17 @@ f_popup_list(typval_T *argvars UNUSED, t
     void
 f_popup_locate(typval_T *argvars, typval_T *rettv)
 {
-    int		row = tv_get_number(&argvars[0]) - 1;
-    int		col = tv_get_number(&argvars[1]) - 1;
+    int		row;
+    int		col;
     win_T	*wp;
 
+    if (in_vim9script()
+	    && (check_for_number_arg(argvars, 0) == FAIL
+		|| check_for_number_arg(argvars, 1) == FAIL))
+	return;
+
+    row = tv_get_number(&argvars[0]) - 1;
+    col = tv_get_number(&argvars[1]) - 1;
     wp = mouse_find_win(&row, &col, FIND_POPUP);
     if (wp != NULL && WIN_IS_POPUP(wp))
 	rettv->vval.v_number = wp->w_id;
@@ -3003,13 +3033,18 @@ get_moved_list(dict_T *dict, win_T *wp)
 f_popup_getoptions(typval_T *argvars, typval_T *rettv)
 {
     dict_T	*dict;
-    int		id = (int)tv_get_number(argvars);
-    win_T	*wp = find_popup_win(id);
+    int		id;
+    win_T	*wp;
     tabpage_T	*tp;
     int		i;
 
     if (rettv_dict_alloc(rettv) == OK)
     {
+	if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
+	    return;
+
+	id = (int)tv_get_number(argvars);
+	wp = find_popup_win(id);
 	if (wp == NULL)
 	    return;