patch 8.2.3206: Vim9: argument types are not checked at compile time
Problem: Vim9: argument types are not checked at compile time.
Solution: Add several more type checks. (Yegappan Lakshmanan, closes #8611)
diff --git a/src/typval.c b/src/typval.c
index b73c500..e22dd3b 100644
--- a/src/typval.c
+++ b/src/typval.c
@@ -506,23 +506,6 @@
}
/*
- * Give an error and return FAIL unless "args[idx]" is a blob.
- */
- int
-check_for_blob_arg(typval_T *args, int idx)
-{
- if (args[idx].v_type != VAR_BLOB)
- {
- if (idx >= 0)
- semsg(_(e_blob_required_for_argument_nr), idx + 1);
- else
- emsg(_(e_blobreq));
- return FAIL;
- }
- return OK;
-}
-
-/*
* Give an error and return FAIL unless "args[idx]" is a channel or a job.
*/
int
@@ -625,8 +608,7 @@
}
/*
- * Give an error and return FAIL unless "args[idx]" is a string or
- * a blob.
+ * Give an error and return FAIL unless "args[idx]" is a string or a blob.
*/
int
check_for_string_or_blob_arg(typval_T *args, int idx)
@@ -643,8 +625,7 @@
}
/*
- * Give an error and return FAIL unless "args[idx]" is a string or
- * a list.
+ * Give an error and return FAIL unless "args[idx]" is a string or a list.
*/
int
check_for_string_or_list_arg(typval_T *args, int idx)
@@ -661,8 +642,45 @@
}
/*
- * Give an error and return FAIL unless "args[idx]" is a buffer
- * number or a dict.
+ * Give an error and return FAIL unless "args[idx]" is a list or a blob.
+ */
+ int
+check_for_list_or_blob_arg(typval_T *args, int idx)
+{
+ if (args[idx].v_type != VAR_LIST && args[idx].v_type != VAR_BLOB)
+ {
+ if (idx >= 0)
+ semsg(_(e_list_required_for_argument_nr), idx + 1);
+ else
+ emsg(_(e_listreq));
+ return FAIL;
+ }
+ return OK;
+}
+
+/*
+ * Give an error and return FAIL unless "args[idx]" is a list or dict or a
+ * blob.
+ */
+ int
+check_for_list_or_dict_or_blob_arg(typval_T *args, int idx)
+{
+ if (args[idx].v_type != VAR_LIST
+ && args[idx].v_type != VAR_DICT
+ && args[idx].v_type != VAR_BLOB)
+ {
+ if (idx >= 0)
+ semsg(_(e_list_required_for_argument_nr), idx + 1);
+ else
+ emsg(_(e_listreq));
+ return FAIL;
+ }
+ return OK;
+}
+
+/*
+ * Give an error and return FAIL unless "args[idx]" is a buffer number or a
+ * dict.
*/
int
check_for_buffer_or_dict_arg(typval_T *args, int idx)