0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.2250: Vim9: sublist is ambiguous

Problem:    Vim9: sublist is ambiguous.
Solution:   Require white space around the colon. (closes #7409)
This commit is contained in:
Bram Moolenaar 2020-12-30 20:39:21 +01:00
parent 2a5c61a019
commit de4f95b041
5 changed files with 111 additions and 72 deletions

View File

@ -3725,6 +3725,7 @@ eval_index(
int range = FALSE;
char_u *key = NULL;
int keylen = -1;
int vim9 = in_vim9script();
if (check_can_index(rettv, evaluate, verbose) == FAIL)
return FAIL;
@ -3755,6 +3756,12 @@ eval_index(
empty1 = TRUE;
else if (eval1(arg, &var1, evalarg) == FAIL) // recursive!
return FAIL;
else if (vim9 && **arg == ':')
{
semsg(_(e_white_space_required_before_and_after_str), ":");
clear_tv(&var1);
return FAIL;
}
else if (evaluate && tv_get_string_chk(&var1) == NULL)
{
// not a number or string
@ -3769,7 +3776,15 @@ eval_index(
if (**arg == ':')
{
range = TRUE;
*arg = skipwhite_and_linebreak(*arg + 1, evalarg);
++*arg;
if (!IS_WHITE_OR_NUL(**arg) && **arg != ']')
{
semsg(_(e_white_space_required_before_and_after_str), ":");
if (!empty1)
clear_tv(&var1);
return FAIL;
}
*arg = skipwhite_and_linebreak(*arg, evalarg);
if (**arg == ']')
empty2 = TRUE;
else if (eval1(arg, &var2, evalarg) == FAIL) // recursive!

View File

@ -1718,6 +1718,15 @@ def Test_expr7_list()
Main()
END
CheckScriptFailure(lines, 'E1127:')
lines =<< trim END
var numbers = [1, 2, 3, 4]
var a = 1
var b = 2
END
CheckDefAndScriptFailure(lines + ['echo numbers[1:b]'], 'E1004:', 4)
CheckDefAndScriptFailure(lines + ['echo numbers[1: b]'], 'E1004:', 4)
CheckDefAndScriptFailure(lines + ['echo numbers[a :b]'], 'E1004:', 4)
enddef
def Test_expr7_list_vim9script()

View File

@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2250,
/**/
2249,
/**/

View File

@ -3695,19 +3695,33 @@ compile_subscript(
if (may_get_next_line_error(p, arg, cctx) == FAIL)
return FAIL;
if (**arg == ':')
{
// missing first index is equal to zero
generate_PUSHNR(cctx, 0);
}
else
{
if (compile_expr0(arg, cctx) == FAIL)
return FAIL;
if (**arg == ':')
{
semsg(_(e_white_space_required_before_and_after_str), ":");
return FAIL;
}
if (may_get_next_line_error(p, arg, cctx) == FAIL)
return FAIL;
*arg = skipwhite(*arg);
}
if (**arg == ':')
{
*arg = skipwhite(*arg + 1);
is_slice = TRUE;
++*arg;
if (!IS_WHITE_OR_NUL(**arg) && **arg != ']')
{
semsg(_(e_white_space_required_before_and_after_str), ":");
return FAIL;
}
*arg = skipwhite(*arg);
if (may_get_next_line_error(p, arg, cctx) == FAIL)
return FAIL;
if (**arg == ']')
@ -3721,7 +3735,6 @@ compile_subscript(
return FAIL;
*arg = skipwhite(*arg);
}
is_slice = TRUE;
}
if (**arg != ']')