patch 8.2.3221: 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 #8632)
diff --git a/src/typval.c b/src/typval.c
index 61f8eb5..abda5f0 100644
--- a/src/typval.c
+++ b/src/typval.c
@@ -422,6 +422,23 @@
}
/*
+ * Give an error and return FAIL unless "args[idx]" is a float or a number.
+ */
+ int
+check_for_float_or_nr_arg(typval_T *args, int idx)
+{
+ if (args[idx].v_type != VAR_FLOAT && args[idx].v_type != VAR_NUMBER)
+ {
+ if (idx >= 0)
+ semsg(_(e_number_required_for_argument_nr), idx + 1);
+ else
+ emsg(_(e_numberreq));
+ return FAIL;
+ }
+ return OK;
+}
+
+/*
* Give an error and return FAIL unless "args[idx]" is a bool.
*/
int
@@ -653,6 +670,16 @@
}
/*
+ * Check for an optional string or list argument at 'idx'
+ */
+ int
+check_for_opt_string_or_list_arg(typval_T *args, int idx)
+{
+ return (args[idx].v_type == VAR_UNKNOWN
+ || check_for_string_or_list_arg(args, idx));
+}
+
+/*
* Give an error and return FAIL unless "args[idx]" is a list or a blob.
*/
int