patch 9.0.2076: Vim9: No support for type aliases
Problem: Vim9: No support for type aliases
Solution: Implement :type command
A type definition is giving a name to a type specification. This also known
type alias.
:type ListOfStrings = list<string>
The type alias can be used wherever a built-in type can be used. The type
alias name must start with an upper case character.
closes: #13407
Signed-off-by: Christian Brabandt <cb@256bit.org>
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 4aa8360..a4ed449 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1327,11 +1327,12 @@
/*
* Generate the load instruction for "name".
*/
- static void
+ static int
generate_loadvar(cctx_T *cctx, lhs_T *lhs)
{
char_u *name = lhs->lhs_name;
type_T *type = lhs->lhs_type;
+ int res = OK;
switch (lhs->lhs_dest)
{
@@ -1360,7 +1361,7 @@
generate_LOAD(cctx, ISN_LOADT, 0, name + 2, type);
break;
case dest_script:
- compile_load_scriptvar(cctx,
+ res = compile_load_scriptvar(cctx,
name + (name[1] == ':' ? 2 : 0), NULL, NULL);
break;
case dest_env:
@@ -1392,6 +1393,8 @@
// list or dict value should already be on the stack.
break;
}
+
+ return res;
}
/*
@@ -2240,10 +2243,11 @@
&& need_type(rhs_type, member_type, FALSE,
-3, 0, cctx, FALSE, FALSE) == FAIL)
return FAIL;
+
+ return OK;
}
- else
- generate_loadvar(cctx, lhs);
- return OK;
+
+ return generate_loadvar(cctx, lhs);
}
/*
@@ -2301,7 +2305,8 @@
return generate_CLASSMEMBER(cctx, TRUE, cl, lhs->lhs_member_idx);
}
- compile_load_lhs(lhs, var_start, NULL, cctx);
+ if (compile_load_lhs(lhs, var_start, NULL, cctx) == FAIL)
+ return FAIL;
if (lhs->lhs_has_index)
{
@@ -2510,6 +2515,7 @@
case VAR_VOID:
case VAR_INSTR:
case VAR_CLASS:
+ case VAR_TYPEALIAS:
case VAR_SPECIAL: // cannot happen
// This is skipped for local variables, they are always
// initialized to zero. But in a "for" or "while" loop
@@ -3963,6 +3969,11 @@
line = (char_u *)"";
break;
+ case CMD_type:
+ emsg(_(e_type_can_only_be_used_in_script));
+ goto erret;
+ break;
+
case CMD_global:
if (check_global_and_subst(ea.cmd, p) == FAIL)
goto erret;