summaryrefslogtreecommitdiffstats
path: root/src/vim9type.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2023-01-07 12:08:41 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-07 12:08:41 +0000
commiteca2c5fff6f6ccad0df8824c4b4354d3f410d225 (patch)
treef4c0f3d3e7d5b1fd756fb36234a455ab220efb8c /src/vim9type.c
parent2c01131c2a9d5455de603f646ba8a2be59282faf (diff)
patch 9.0.1155: cannot use a class as a typev9.0.1155
Problem: Cannot use a class as a type. Solution: Accept a class and interface name as a type.
Diffstat (limited to 'src/vim9type.c')
-rw-r--r--src/vim9type.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/vim9type.c b/src/vim9type.c
index c85c3f6c7d..1078861674 100644
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -1272,6 +1272,30 @@ parse_type(char_u **arg, garray_T *type_gap, int give_error)
break;
}
+ // It can be a class or interface name.
+ typval_T tv;
+ tv.v_type = VAR_UNKNOWN;
+ if (eval_variable(*arg, len, 0, &tv, NULL,
+ EVAL_VAR_VERBOSE + EVAL_VAR_IMPORT) == OK)
+ {
+ if (tv.v_type == VAR_CLASS && tv.vval.v_class != NULL)
+ {
+ type_T *type = get_type_ptr(type_gap);
+ if (type != NULL)
+ {
+ // Although the name is that of a class or interface, the type
+ // uses will be an object.
+ type->tt_type = VAR_OBJECT;
+ type->tt_member = (type_T *)tv.vval.v_class;
+ clear_tv(&tv);
+ *arg += len;
+ return type;
+ }
+ }
+
+ clear_tv(&tv);
+ }
+
if (give_error)
semsg(_(e_type_not_recognized_str), *arg);
return NULL;