mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.3347: check for legacy script is incomplete
Problem: Check for legacy script is incomplete. (Naohiro Ono) Solution: Also check the :legacy modifier. Use for string concatenation with "." and others (issue #8756)
This commit is contained in:
parent
2596a4e763
commit
dd9de50f42
@ -650,3 +650,5 @@ EXTERN char e_argument_of_exists_compiled_must_be_literal_string[]
|
|||||||
INIT(= N_("E1232: Argument of exists_compiled() must be a literal string"));
|
INIT(= N_("E1232: Argument of exists_compiled() must be a literal string"));
|
||||||
EXTERN char e_exists_compiled_can_only_be_used_in_def_function[]
|
EXTERN char e_exists_compiled_can_only_be_used_in_def_function[]
|
||||||
INIT(= N_("E1233: exists_compiled() can only be used in a :def function"));
|
INIT(= N_("E1233: exists_compiled() can only be used in a :def function"));
|
||||||
|
EXTERN char e_legacy_must_be_followed_by_command[]
|
||||||
|
INIT(= N_("E1234: legacy must be followed by a command"));
|
||||||
|
@ -2860,8 +2860,7 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
|||||||
// "++" and "--" on the next line are a separate command.
|
// "++" and "--" on the next line are a separate command.
|
||||||
p = eval_next_non_blank(*arg, evalarg, &getnext);
|
p = eval_next_non_blank(*arg, evalarg, &getnext);
|
||||||
op = *p;
|
op = *p;
|
||||||
concat = op == '.' && (*(p + 1) == '.'
|
concat = op == '.' && (*(p + 1) == '.' || in_old_script(2));
|
||||||
|| (current_sctx.sc_version < 2 && !vim9script));
|
|
||||||
if ((op != '+' && op != '-' && !concat) || p[1] == '='
|
if ((op != '+' && op != '-' && !concat) || p[1] == '='
|
||||||
|| (p[1] == '.' && p[2] == '='))
|
|| (p[1] == '.' && p[2] == '='))
|
||||||
break;
|
break;
|
||||||
@ -3402,7 +3401,7 @@ eval7(
|
|||||||
|
|
||||||
if (**arg == '.' && (!isdigit(*(*arg + 1))
|
if (**arg == '.' && (!isdigit(*(*arg + 1))
|
||||||
#ifdef FEAT_FLOAT
|
#ifdef FEAT_FLOAT
|
||||||
|| current_sctx.sc_version < 2
|
|| in_old_script(2)
|
||||||
#endif
|
#endif
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
@ -5877,7 +5876,7 @@ handle_subscript(
|
|||||||
|| (**arg == '.' && (rettv->v_type == VAR_DICT
|
|| (**arg == '.' && (rettv->v_type == VAR_DICT
|
||||||
|| (!evaluate
|
|| (!evaluate
|
||||||
&& (*arg)[1] != '.'
|
&& (*arg)[1] != '.'
|
||||||
&& current_sctx.sc_version >= 2))))
|
&& !in_old_script(2)))))
|
||||||
{
|
{
|
||||||
dict_unref(selfdict);
|
dict_unref(selfdict);
|
||||||
if (rettv->v_type == VAR_DICT)
|
if (rettv->v_type == VAR_DICT)
|
||||||
|
@ -774,7 +774,7 @@ ex_let(exarg_T *eap)
|
|||||||
--argend;
|
--argend;
|
||||||
expr = skipwhite(argend);
|
expr = skipwhite(argend);
|
||||||
concat = expr[0] == '.'
|
concat = expr[0] == '.'
|
||||||
&& ((expr[1] == '=' && current_sctx.sc_version < 2)
|
&& ((expr[1] == '=' && in_old_script(2))
|
||||||
|| (expr[1] == '.' && expr[2] == '='));
|
|| (expr[1] == '.' && expr[2] == '='));
|
||||||
has_assign = *expr == '=' || (vim_strchr((char_u *)"+-*/%", *expr) != NULL
|
has_assign = *expr == '=' || (vim_strchr((char_u *)"+-*/%", *expr) != NULL
|
||||||
&& expr[1] == '=');
|
&& expr[1] == '=');
|
||||||
@ -2932,7 +2932,7 @@ find_var_ht(char_u *name, char_u **varname)
|
|||||||
|
|
||||||
// "version" is "v:version" in all scopes if scriptversion < 3.
|
// "version" is "v:version" in all scopes if scriptversion < 3.
|
||||||
// Same for a few other variables marked with VV_COMPAT.
|
// Same for a few other variables marked with VV_COMPAT.
|
||||||
if (current_sctx.sc_version < 3)
|
if (in_old_script(3))
|
||||||
{
|
{
|
||||||
hi = hash_find(&compat_hashtab, name);
|
hi = hash_find(&compat_hashtab, name);
|
||||||
if (!HASHITEM_EMPTY(hi))
|
if (!HASHITEM_EMPTY(hi))
|
||||||
|
@ -2951,7 +2951,7 @@ parse_command_modifiers(
|
|||||||
if (ends_excmd2(p, eap->cmd))
|
if (ends_excmd2(p, eap->cmd))
|
||||||
{
|
{
|
||||||
*errormsg =
|
*errormsg =
|
||||||
_(e_vim9cmd_must_be_followed_by_command);
|
_(e_legacy_must_be_followed_by_command);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
cmod->cmod_flags |= CMOD_LEGACY;
|
cmod->cmod_flags |= CMOD_LEGACY;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/* vim9script.c */
|
/* vim9script.c */
|
||||||
int in_vim9script(void);
|
int in_vim9script(void);
|
||||||
|
int in_old_script(int max_version);
|
||||||
int current_script_is_vim9(void);
|
int current_script_is_vim9(void);
|
||||||
void ex_vim9script(exarg_T *eap);
|
void ex_vim9script(exarg_T *eap);
|
||||||
int not_in_vim9(exarg_T *eap);
|
int not_in_vim9(exarg_T *eap);
|
||||||
|
@ -13,9 +13,25 @@ def Test_vim9cmd()
|
|||||||
vim9cm assert_equal('yes', y)
|
vim9cm assert_equal('yes', y)
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
assert_fails('vim9cmd', 'E1164:')
|
assert_fails('vim9cmd', 'E1164:')
|
||||||
|
assert_fails('legacy', 'E1234:')
|
||||||
assert_fails('vim9cmd echo "con" . "cat"', 'E15:')
|
assert_fails('vim9cmd echo "con" . "cat"', 'E15:')
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
let str = 'con'
|
||||||
|
vim9cmd str .= 'cat'
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E492:')
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
legacy echo "con" . "cat"
|
||||||
|
legacy let str = 'con'
|
||||||
|
legacy let str .= 'cat'
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
def Foo()
|
def Foo()
|
||||||
@ -24,11 +40,47 @@ def Test_vim9cmd()
|
|||||||
nmap ,; :vim9cmd <SID>Foo()<CR>
|
nmap ,; :vim9cmd <SID>Foo()<CR>
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
feedkeys(',;', 'xt')
|
feedkeys(',;', 'xt')
|
||||||
assert_equal("bar", g:found_bar)
|
assert_equal("bar", g:found_bar)
|
||||||
|
|
||||||
nunmap ,;
|
nunmap ,;
|
||||||
unlet g:found_bar
|
unlet g:found_bar
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
legacy echo 1'000
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E115:')
|
||||||
|
|
||||||
|
if has('float')
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
echo .10
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
lines =<< trim END
|
||||||
|
vim9cmd echo .10
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
legacy echo .10
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E15:')
|
||||||
|
endif
|
||||||
|
|
||||||
|
echo v:version
|
||||||
|
assert_fails('vim9cmd echo version', 'E121:')
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
echo version
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E121:')
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
legacy echo version
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_edit_wildcards()
|
def Test_edit_wildcards()
|
||||||
|
@ -1704,7 +1704,7 @@ eval_number(
|
|||||||
int want_string UNUSED)
|
int want_string UNUSED)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
int skip_quotes = current_sctx.sc_version >= 4 || in_vim9script();
|
int skip_quotes = !in_old_script(4);
|
||||||
#ifdef FEAT_FLOAT
|
#ifdef FEAT_FLOAT
|
||||||
char_u *p;
|
char_u *p;
|
||||||
int get_float = FALSE;
|
int get_float = FALSE;
|
||||||
|
@ -755,6 +755,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3347,
|
||||||
/**/
|
/**/
|
||||||
3346,
|
3346,
|
||||||
/**/
|
/**/
|
||||||
|
@ -33,6 +33,18 @@ in_vim9script(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(FEAT_EVAL) || defined(PROTO)
|
#if defined(FEAT_EVAL) || defined(PROTO)
|
||||||
|
/*
|
||||||
|
* Return TRUE when currently in a script with script version smaller than
|
||||||
|
* "max_version" or command modifiers forced it.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
in_old_script(int max_version)
|
||||||
|
{
|
||||||
|
return (current_sctx.sc_version <= max_version
|
||||||
|
&& !(cmdmod.cmod_flags & CMOD_VIM9CMD))
|
||||||
|
|| (cmdmod.cmod_flags & CMOD_LEGACY);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return TRUE if the current script is Vim9 script.
|
* Return TRUE if the current script is Vim9 script.
|
||||||
* This also returns TRUE in a legacy function in a Vim9 script.
|
* This also returns TRUE in a legacy function in a Vim9 script.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user