mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
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>
This commit is contained in:
committed by
Christian Brabandt
parent
4bca4897a1
commit
ec3cebbd2b
@@ -1327,11 +1327,12 @@ assignment_len(char_u *p, int *heredoc)
|
||||
/*
|
||||
* 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_loadvar(cctx_T *cctx, lhs_T *lhs)
|
||||
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 @@ generate_loadvar(cctx_T *cctx, lhs_T *lhs)
|
||||
// list or dict value should already be on the stack.
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2240,10 +2243,11 @@ compile_load_lhs(
|
||||
&& 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 @@ compile_load_lhs_with_index(lhs_T *lhs, char_u *var_start, cctx_T *cctx)
|
||||
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 @@ push_default_value(
|
||||
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 @@ compile_def_function(
|
||||
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;
|
||||
|
Reference in New Issue
Block a user