1
0
forked from aniani/vim

patch 9.1.1274: Vim9: no support for object<type> as variable type

Problem:  Vim9: no support for object<type> as variable type
Solution: add support for object<type> (Yegappan Lakshmanan)

closes: #17041

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Yegappan Lakshmanan
2025-04-03 21:26:34 +02:00
committed by Christian Brabandt
parent f16d8b2dda
commit 6fa62085ff
6 changed files with 250 additions and 2 deletions

View File

@@ -1784,6 +1784,63 @@ on_err:
return ret_type;
}
/*
* Parse a "object" type at "*arg" and advance over it.
* When "give_error" is TRUE give error messages, otherwise be quiet.
* Return NULL for failure.
*/
static type_T *
parse_type_object(char_u **arg, garray_T *type_gap, int give_error)
{
char_u *arg_start = *arg;
type_T *object_type;
int prev_called_emsg = called_emsg;
// object<X> or object<any>
if (**arg != '<')
{
if (give_error)
{
if (*skipwhite(*arg) == '<')
semsg(_(e_no_white_space_allowed_before_str_str), "<", *arg);
else
semsg(_(e_missing_type_after_str), "object");
}
// only "object" is specified
return NULL;
}
// skip spaces following "object<"
*arg = skipwhite(*arg + 1);
object_type = parse_type(arg, type_gap, give_error);
if (object_type == NULL)
return NULL;
*arg = skipwhite(*arg);
if (**arg != '>' && called_emsg == prev_called_emsg)
{
if (give_error)
semsg(_(e_missing_gt_after_type_str), arg_start);
return NULL;
}
++*arg;
if (object_type->tt_type == VAR_ANY)
return &t_object_any;
if (object_type->tt_type != VAR_OBJECT)
{
// specified type is not a class
if (give_error)
semsg(_(e_class_name_not_found_str), arg_start);
return NULL;
}
return object_type;
}
/*
* Parse a user defined type at "*arg" and advance over it.
* It can be a class or an interface or a typealias name, possibly imported.
@@ -1932,6 +1989,13 @@ parse_type(char_u **arg, garray_T *type_gap, int give_error)
return &t_number;
}
break;
case 'o':
if (len == 6 && STRNCMP(*arg, "object", len) == 0)
{
*arg += len;
return parse_type_object(arg, type_gap, give_error);
}
break;
case 's':
if (len == 6 && STRNCMP(*arg, "string", len) == 0)
{