summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-02-20 22:54:43 +0100
committerBram Moolenaar <Bram@vim.org>2020-02-20 22:54:43 +0100
commit436472f5e0328dc4a635b1c344c04a62d64132ea (patch)
tree15c52d18892b26f6c47035c5d93ea56c26692947
parent85683ec620be199d63af3b0542a03eeb72b08fb6 (diff)
patch 8.2.0291: Vim9: assigning [] to list<string> doesn't workv8.2.0291
Problem: Vim9: assigning [] to list<string> doesn't work. Solution: Use void for empty list and dict. (Ken Takata, closes #5669)
-rw-r--r--src/globals.h6
-rw-r--r--src/testdir/test_vim9_script.vim5
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c25
4 files changed, 26 insertions, 12 deletions
diff --git a/src/globals.h b/src/globals.h
index fc551ba996..785b69f6e7 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -400,6 +400,8 @@ EXTERN type_T t_partial_any INIT4(VAR_PARTIAL, -1, &t_any, NULL);
EXTERN type_T t_list_any INIT4(VAR_LIST, 0, &t_any, NULL);
EXTERN type_T t_dict_any INIT4(VAR_DICT, 0, &t_any, NULL);
+EXTERN type_T t_list_empty INIT4(VAR_LIST, 0, &t_void, NULL);
+EXTERN type_T t_dict_empty INIT4(VAR_DICT, 0, &t_void, NULL);
EXTERN type_T t_list_number INIT4(VAR_LIST, 0, &t_number, NULL);
EXTERN type_T t_list_string INIT4(VAR_LIST, 0, &t_string, NULL);
@@ -1496,7 +1498,7 @@ EXTERN int netbeansSuppressNoLines INIT(= 0); // skip "No lines in buffer"
* Excluded are errors that are only used once and debugging messages.
*/
EXTERN char e_abort[] INIT(= N_("E470: Command aborted"));
-EXTERN char e_argreq[] INIT(= N_("E471: Argument required"));
+EXTERN char e_argreq[] INIT(= N_("E471: Argument required"));
EXTERN char e_backslash[] INIT(= N_("E10: \\ should be followed by /, ? or &"));
#ifdef FEAT_CMDWIN
EXTERN char e_cmdwin[] INIT(= N_("E11: Invalid in command-line window; <CR> executes, CTRL-C quits"));
@@ -1639,7 +1641,7 @@ EXTERN char e_invalblob[] INIT(= N_("E978: Invalid operation for Blob"));
EXTERN char e_toomanyarg[] INIT(= N_("E118: Too many arguments for function: %s"));
EXTERN char e_toofewarg[] INIT(= N_("E119: Not enough arguments for function: %s"));
EXTERN char e_func_deleted[] INIT(= N_("E933: Function was deleted: %s"));
-EXTERN char e_dictkey[] INIT(= N_("E716: Key not present in Dictionary: %s"));
+EXTERN char e_dictkey[] INIT(= N_("E716: Key not present in Dictionary: %s"));
EXTERN char e_listreq[] INIT(= N_("E714: List required"));
EXTERN char e_listblobreq[] INIT(= N_("E897: List or Blob required"));
EXTERN char e_listdictarg[] INIT(= N_("E712: Argument of %s must be a List or Dictionary"));
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 3212c3de20..6ae4273b90 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -40,9 +40,8 @@ def Test_assignment()
let list1: list<string> = ['sdf', 'asdf']
let list2: list<number> = [1, 2, 3]
- " TODO: does not work yet
- " let listS: list<string> = []
- " let listN: list<number> = []
+ let listS: list<string> = []
+ let listN: list<number> = []
let dict1: dict<string> = #{key: 'value'}
let dict2: dict<number> = #{one: 1, two: 2}
diff --git a/src/version.c b/src/version.c
index 58b84d054f..3cab8b02aa 100644
--- a/src/version.c
+++ b/src/version.c
@@ -739,6 +739,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 291,
+/**/
290,
/**/
289,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 912f8cad28..e354944547 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -211,6 +211,8 @@ get_list_type(type_T *member_type, garray_T *type_list)
// recognize commonly used types
if (member_type->tt_type == VAR_UNKNOWN)
return &t_list_any;
+ if (member_type->tt_type == VAR_VOID)
+ return &t_list_empty;
if (member_type->tt_type == VAR_NUMBER)
return &t_list_number;
if (member_type->tt_type == VAR_STRING)
@@ -234,6 +236,8 @@ get_dict_type(type_T *member_type, garray_T *type_list)
// recognize commonly used types
if (member_type->tt_type == VAR_UNKNOWN)
return &t_dict_any;
+ if (member_type->tt_type == VAR_VOID)
+ return &t_dict_empty;
if (member_type->tt_type == VAR_NUMBER)
return &t_dict_number;
if (member_type->tt_type == VAR_STRING)
@@ -813,11 +817,12 @@ generate_NEWLIST(cctx_T *cctx, int count)
// drop the value types
stack->ga_len -= count;
- // use the first value type for the list member type
+ // Use the first value type for the list member type. Use "void" for an
+ // empty list.
if (count > 0)
member = ((type_T **)stack->ga_data)[stack->ga_len];
else
- member = &t_any;
+ member = &t_void;
type = get_list_type(member, type_list);
// add the list type to the type stack
@@ -848,11 +853,12 @@ generate_NEWDICT(cctx_T *cctx, int count)
// drop the key and value types
stack->ga_len -= 2 * count;
- // use the first value type for the list member type
+ // Use the first value type for the list member type. Use "void" for an
+ // empty dict.
if (count > 0)
member = ((type_T **)stack->ga_data)[stack->ga_len + 1];
else
- member = &t_any;
+ member = &t_void;
type = get_dict_type(member, type_list);
// add the dict type to the type stack
@@ -1854,8 +1860,13 @@ check_type(type_T *expected, type_T *actual, int give_msg)
}
if (expected->tt_type == VAR_DICT || expected->tt_type == VAR_LIST)
{
- int ret = check_type(expected->tt_member, actual->tt_member,
- FALSE);
+ int ret;
+
+ // void is used for an empty list or dict
+ if (actual->tt_member == &t_void)
+ ret = OK;
+ else
+ ret = check_type(expected->tt_member, actual->tt_member, FALSE);
if (ret == FAIL && give_msg)
type_mismatch(expected, actual);
return ret;
@@ -1873,7 +1884,7 @@ check_type(type_T *expected, type_T *actual, int give_msg)
static int
need_type(type_T *actual, type_T *expected, int offset, cctx_T *cctx)
{
- if (equal_type(actual, expected) || expected->tt_type == VAR_UNKNOWN)
+ if (check_type(expected, actual, FALSE))
return OK;
if (actual->tt_type != VAR_UNKNOWN)
{