diff options
author | Ernie Rael <errael@raelity.com> | 2023-12-11 17:40:46 +0100 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-12-11 17:40:46 +0100 |
commit | 9ed53752df1020a6881ac68d1bde2852c9a680aa (patch) | |
tree | a99975a155438cacfc942a073910e1e038ed8f5a /src/vim9type.c | |
parent | fa920da283f6651083b40d0aa28a9eacd5116593 (diff) |
patch 9.0.2156: Vim9: can use typealias in assignmentv9.0.2156
Problem: Vim9: can use typealias in an assignment
Solution: Generate errors when class/typealias involved in the rhs of an
assignment
closes: #13637
Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Generate errors when class/typealias involved in assignment.
Diffstat (limited to 'src/vim9type.c')
-rw-r--r-- | src/vim9type.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/vim9type.c b/src/vim9type.c index c28137fcc7..a142a7b9c3 100644 --- a/src/vim9type.c +++ b/src/vim9type.c @@ -1846,4 +1846,66 @@ f_typename(typval_T *argvars, typval_T *rettv) clear_type_list(&type_list); } +/* + * Check if the typval_T is a value type; report an error if it is not. + * Note: a type, user defined or typealias, is not a value type. + * + * Return OK if it's a value type, else FAIL + */ + int +check_typval_is_value(typval_T *tv) +{ + if (tv->v_type == VAR_CLASS) + { + semsg(_(e_using_class_as_value_str), tv->vval.v_class->class_name); + return FAIL; + } + else if (tv->v_type == VAR_TYPEALIAS) + { + semsg(_(e_using_typealias_as_value_str), tv->vval.v_typealias->ta_name); + return FAIL; + } + return OK; +} + +/* + * Same as above, except check type_T. + */ + int +check_type_is_value(type_T *type) +{ + if (type->tt_type == VAR_CLASS) + { + semsg(_(e_using_class_as_value_str), type->tt_class->class_name); + return FAIL; + } + else if (type->tt_type == VAR_TYPEALIAS) + { + // Not sure what could be done here to get a name + // TODO: 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 |