summaryrefslogtreecommitdiffstats
path: root/src/vim9type.c
diff options
context:
space:
mode:
authorErnie Rael <errael@raelity.com>2023-12-16 14:03:33 +0100
committerChristian Brabandt <cb@256bit.org>2023-12-16 14:03:33 +0100
commitd8bf87c9fbd92fd6b837446e886d47e557adadbc (patch)
tree0a3ef3beef2fa291e2851bc5764a7bbb15b99e11 /src/vim9type.c
parentdf12e39b8b9dd39056e22b452276622cb7b617fd (diff)
patch 9.0.2169: Vim9: builtin funcs may accept a non-valuev9.0.2169
Problem: Vim9: builtin funcs may accept a non-value Solution: Restrict builtin functions that accept `type` This PR finishes off detection and prevention of using a type as a value. It takes care of builtin functions. However there are some builtin functions, that need to be able to handle types as well as non-args: instanceof(), type(), typename(), string(). A "bit", FE_X, is added to funcentry_T; when set, the builtin function can handle a type (class or type-alias) in addition to a value. Noteworthy change: Discovered that in compile_call() the builtin add() is compiled inline instead of calling the builtin. Had to add a check there. closes: #13688 Signed-off-by: Ernie Rael <errael@raelity.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/vim9type.c')
-rw-r--r--src/vim9type.c27
1 files changed, 6 insertions, 21 deletions
diff --git a/src/vim9type.c b/src/vim9type.c
index 8840c37ccc..423043a84a 100644
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -1867,6 +1867,8 @@ f_typename(typval_T *argvars, typval_T *rettv)
int
check_typval_is_value(typval_T *tv)
{
+ if (tv == NULL)
+ return OK;
if (tv->v_type == VAR_CLASS)
{
semsg(_(e_using_class_as_value_str), tv->vval.v_class->class_name);
@@ -1886,6 +1888,8 @@ check_typval_is_value(typval_T *tv)
int
check_type_is_value(type_T *type)
{
+ if (type == NULL)
+ return OK;
if (type->tt_type == VAR_CLASS)
{
semsg(_(e_using_class_as_value_str), type->tt_class->class_name);
@@ -1893,31 +1897,12 @@ check_type_is_value(type_T *type)
}
else if (type->tt_type == VAR_TYPEALIAS)
{
- // Not sure what could be done here to get a name
- // TODO: MAYBE AN OPTIONAL ARGUMENT
+ // TODO: Not sure what could be done here to get a name.
+ // Maybe an optional argument?
emsg(_(e_using_typealias_as_var_val));
return FAIL;
}
return OK;
}
-/*
- * Same as above, except check vartype_T.
- */
- int
-check_vartype_is_value(vartype_T typ)
-{
- if (typ == VAR_CLASS)
- {
- emsg(_(e_using_class_as_var_val));
- return FAIL;
- }
- else if (typ == VAR_TYPEALIAS)
- {
- emsg(_(e_using_typealias_as_var_val));
- return FAIL;
- }
- return OK;
-}
-
#endif // FEAT_EVAL