summaryrefslogtreecommitdiffstats
path: root/src/evalvars.c
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2023-10-27 19:35:26 +0200
committerChristian Brabandt <cb@256bit.org>2023-10-27 19:35:26 +0200
commitec3cebbd2b6b7583d2f683f5e66345163ec122aa (patch)
tree66f0c9b69e88fa4a0d35ae738f687b5679bc56e0 /src/evalvars.c
parent4bca4897a12dfb91b3b27e3083fd5f370bd857d1 (diff)
patch 9.0.2076: Vim9: No support for type aliasesv9.0.2076
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>
Diffstat (limited to 'src/evalvars.c')
-rw-r--r--src/evalvars.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index d7a1a96a54..5c7bc12d2f 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -158,6 +158,7 @@ static struct vimvar
{VV_NAME("sizeofpointer", VAR_NUMBER), NULL, VV_RO},
{VV_NAME("maxcol", VAR_NUMBER), NULL, VV_RO},
{VV_NAME("python3_version", VAR_NUMBER), NULL, VV_RO},
+ {VV_NAME("t_typealias", VAR_NUMBER), NULL, VV_RO},
};
// shorthand
@@ -260,6 +261,7 @@ evalvars_init(void)
set_vim_var_nr(VV_TYPE_BLOB, VAR_TYPE_BLOB);
set_vim_var_nr(VV_TYPE_CLASS, VAR_TYPE_CLASS);
set_vim_var_nr(VV_TYPE_OBJECT, VAR_TYPE_OBJECT);
+ set_vim_var_nr(VV_TYPE_TYPEALIAS, VAR_TYPE_TYPEALIAS);
set_vim_var_nr(VV_ECHOSPACE, sc_col - 1);
@@ -1834,6 +1836,12 @@ ex_let_one(
return NULL;
}
+ if (tv->v_type == VAR_TYPEALIAS)
+ {
+ semsg(_(e_using_typealias_as_variable), tv->vval.v_typealias->ta_name);
+ return NULL;
+ }
+
if (*arg == '$')
{
// ":let $VAR = expr": Set environment variable.
@@ -2331,6 +2339,7 @@ item_lock(typval_T *tv, int deep, int lock, int check_refcount)
case VAR_INSTR:
case VAR_CLASS:
case VAR_OBJECT:
+ case VAR_TYPEALIAS:
break;
case VAR_BLOB:
@@ -2998,7 +3007,7 @@ eval_variable(
}
// Check for local variable when debugging.
- if ((tv = lookup_debug_var(name)) == NULL)
+ if ((sid == 0) && (tv = lookup_debug_var(name)) == NULL)
{
// Check for user-defined variables.
dictitem_T *v = find_var(name, &ht, flags & EVAL_VAR_NOAUTOLOAD);
@@ -3114,6 +3123,25 @@ eval_variable(
}
}
+ if ((tv->v_type == VAR_TYPEALIAS || tv->v_type == VAR_CLASS)
+ && sid != 0)
+ {
+ // type alias or class imported from another script. Check
+ // whether it is exported from the other script.
+ sv = find_typval_in_script(tv, sid, TRUE);
+ if (sv == NULL)
+ {
+ ret = FAIL;
+ goto done;
+ }
+ if ((sv->sv_flags & SVFLAG_EXPORTED) == 0)
+ {
+ semsg(_(e_item_not_exported_in_script_str), name);
+ ret = FAIL;
+ goto done;
+ }
+ }
+
// If a list or dict variable wasn't initialized and has meaningful
// type, do it now. Not for global variables, they are not
// declared.
@@ -3162,6 +3190,7 @@ eval_variable(
}
}
+done:
if (len > 0)
name[len] = cc;
@@ -3948,6 +3977,14 @@ set_var_const(
goto failed;
}
+ if (di->di_tv.v_type == VAR_TYPEALIAS)
+ {
+ semsg(_(e_using_typealias_as_variable),
+ di->di_tv.vval.v_typealias->ta_name);
+ clear_tv(&di->di_tv);
+ goto failed;
+ }
+
if (var_in_vim9script && (flags & ASSIGN_FOR_LOOP) == 0)
{
where_T where = WHERE_INIT;