patch 9.0.2078: several problems with type aliases
Problem: several problems with type aliases
Solution: Check for more error conditions, add tests,
fix issues
Check for more error conditions and add additional tests
fixes #13434
fixes #13437
fixes #13438
closes #13441
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/typval.c b/src/typval.c
index da5d7af..078e2eb 100644
--- a/src/typval.c
+++ b/src/typval.c
@@ -271,7 +271,7 @@
emsg(_(e_cannot_use_void_value));
break;
case VAR_TYPEALIAS:
- semsg(_(e_using_typealias_as_variable),
+ semsg(_(e_using_typealias_as_number),
varp->vval.v_typealias->ta_name);
break;
case VAR_UNKNOWN:
@@ -392,7 +392,7 @@
emsg(_(e_cannot_use_void_value));
break;
case VAR_TYPEALIAS:
- semsg(_(e_using_typealias_as_variable),
+ semsg(_(e_using_typealias_as_float),
varp->vval.v_typealias->ta_name);
break;
case VAR_UNKNOWN:
@@ -1004,12 +1004,23 @@
}
/*
+ * Returns TRUE if "tv" is a type alias for a class
+ */
+ int
+tv_class_alias(typval_T *tv)
+{
+ return tv->v_type == VAR_TYPEALIAS &&
+ tv->vval.v_typealias->ta_type->tt_type == VAR_OBJECT;
+}
+
+/*
* Give an error and return FAIL unless "args[idx]" is a class or a list.
*/
int
check_for_class_or_list_arg(typval_T *args, int idx)
{
- if (args[idx].v_type != VAR_CLASS && args[idx].v_type != VAR_LIST)
+ if (args[idx].v_type != VAR_CLASS && args[idx].v_type != VAR_LIST
+ && !tv_class_alias(&args[idx]))
{
semsg(_(e_list_or_class_required_for_argument_nr), idx + 1);
return FAIL;
@@ -1146,6 +1157,9 @@
emsg(_(e_cannot_use_void_value));
break;
case VAR_TYPEALIAS:
+ semsg(_(e_using_typealias_as_string),
+ varp->vval.v_typealias->ta_name);
+ break;
case VAR_UNKNOWN:
case VAR_ANY:
case VAR_INSTR: