Mercurial > vim
diff src/vim9compile.c @ 33678:7d9d2404a3d4 v9.0.2076
patch 9.0.2076: Vim9: No support for type aliases
Commit: https://github.com/vim/vim/commit/ec3cebbd2b6b7583d2f683f5e66345163ec122aa
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Fri Oct 27 19:35:26 2023 +0200
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>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 27 Oct 2023 19:45:05 +0200 |
parents | fcc8296f36eb |
children | 2fc593290679 |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -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 *lh 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 *lh // 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, 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;