summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-12-19 15:17:21 +0000
committerBram Moolenaar <Bram@vim.org>2021-12-19 15:17:21 +0000
commitf47c5a8e2d8eda7c2c8a9cccf9568eb56c03a0cf (patch)
treed494b8e64cfee58471197e389c0b731f4309cb14
parent265f811f5a2dac81d9698f5202a661a04ed095f1 (diff)
patch 8.2.3852: Vim9: not enough testsv8.2.3852
Problem: Vim9: not enough tests. Solution: Also run existing tests for Vim9 script. Make errors more consistent.
-rw-r--r--src/errors.h2
-rw-r--r--src/eval.c10
-rw-r--r--src/testdir/test_listdict.vim13
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c20
5 files changed, 41 insertions, 6 deletions
diff --git a/src/errors.h b/src/errors.h
index 3fd8e5a01d..31f275d171 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -286,6 +286,8 @@ EXTERN char e_invalid_command[]
#ifdef FEAT_EVAL
EXTERN char e_invalid_command_str[]
INIT(= N_("E476: Invalid command: %s"));
+EXTERN char e_cannot_index_a_funcref[]
+ INIT(= N_("E695: Cannot index a Funcref"));
EXTERN char e_list_value_has_more_items_than_targets[]
INIT(= N_("E710: List value has more items than targets"));
EXTERN char e_list_value_does_not_have_enough_items[]
diff --git a/src/eval.c b/src/eval.c
index d0ad7c6e89..4e720e8e23 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -4026,6 +4026,8 @@ eval_index(
}
else if (evaluate)
{
+ int error = FALSE;
+
#ifdef FEAT_FLOAT
// allow for indexing with float
if (vim9 && rettv->v_type == VAR_DICT
@@ -4035,7 +4037,11 @@ eval_index(
var1.v_type = VAR_STRING;
}
#endif
- if (tv_get_string_chk(&var1) == NULL)
+ if (vim9 && rettv->v_type == VAR_LIST)
+ tv_get_number_chk(&var1, &error);
+ else
+ error = tv_get_string_chk(&var1) == NULL;
+ if (error)
{
// not a number or string
clear_tv(&var1);
@@ -4118,7 +4124,7 @@ check_can_index(typval_T *rettv, int evaluate, int verbose)
case VAR_FUNC:
case VAR_PARTIAL:
if (verbose)
- emsg(_("E695: Cannot index a Funcref"));
+ emsg(_(e_cannot_index_a_funcref));
return FAIL;
case VAR_FLOAT:
#ifdef FEAT_FLOAT
diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim
index de63c79998..ad36cb0bdf 100644
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -1291,12 +1291,19 @@ endfunc
" List and dict indexing tests
func Test_listdict_index()
- call assert_fails('echo function("min")[0]', 'E695:')
- call assert_fails('echo v:true[0]', 'E909:')
+ call CheckLegacyAndVim9Failure(['echo function("min")[0]'], 'E695:')
+ call CheckLegacyAndVim9Failure(['echo v:true[0]'], 'E909:')
+ call CheckLegacyAndVim9Failure(['echo v:null[0]'], 'E909:')
+
let d = {'k' : 10}
call assert_fails('echo d.', 'E15:')
- call assert_fails('echo d[1:2]', 'E719:')
+ call CheckDefAndScriptFailure2(['var d = {k: 10}', 'echo d.'], 'E1127', 'E15:')
+
+ call CheckLegacyAndVim9Failure(['VAR d = {"k": 10}', 'echo d[1 : 2]'], 'E719:')
+
call assert_fails("let v = [4, 6][{-> 1}]", 'E729:')
+ call CheckDefAndScriptFailure2(['var v = [4, 6][() => 1]'], 'E1012', 'E703:')
+
call assert_fails("let v = range(5)[2:[]]", 'E730:')
call assert_fails("let v = range(5)[2:{-> 2}(]", ['E15:', 'E116:'])
call assert_fails("let v = range(5)[2:3", 'E111:')
diff --git a/src/version.c b/src/version.c
index d65a5c1a97..288b23a016 100644
--- a/src/version.c
+++ b/src/version.c
@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3852,
+/**/
3851,
/**/
3850,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index d6fc6d8581..ff96b103d5 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3043,7 +3043,25 @@ compile_member(int is_slice, int *keeping_dict, cctx_T *cctx)
}
else
{
- emsg(_(e_string_list_dict_or_blob_required));
+ switch (vartype)
+ {
+ case VAR_FUNC:
+ case VAR_PARTIAL:
+ emsg(_(e_cannot_index_a_funcref));
+ break;
+ case VAR_BOOL:
+ case VAR_SPECIAL:
+ case VAR_JOB:
+ case VAR_CHANNEL:
+ case VAR_INSTR:
+ case VAR_UNKNOWN:
+ case VAR_ANY:
+ case VAR_VOID:
+ emsg(_(e_cannot_index_special_variable));
+ break;
+ default:
+ emsg(_(e_string_list_dict_or_blob_required));
+ }
return FAIL;
}
return OK;