Skip to content

Commit dd9de50

Browse files
committed
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)
1 parent 2596a4e commit dd9de50

File tree

9 files changed

+77
-9
lines changed

9 files changed

+77
-9
lines changed

src/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,3 +650,5 @@ EXTERN char e_argument_of_exists_compiled_must_be_literal_string[]
650650
INIT(= N_("E1232: Argument of exists_compiled() must be a literal string"));
651651
EXTERN char e_exists_compiled_can_only_be_used_in_def_function[]
652652
INIT(= N_("E1233: exists_compiled() can only be used in a :def function"));
653+
EXTERN char e_legacy_must_be_followed_by_command[]
654+
INIT(= N_("E1234: legacy must be followed by a command"));

src/eval.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,8 +2860,7 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
28602860
// "++" and "--" on the next line are a separate command.
28612861
p = eval_next_non_blank(*arg, evalarg, &getnext);
28622862
op = *p;
2863-
concat = op == '.' && (*(p + 1) == '.'
2864-
|| (current_sctx.sc_version < 2 && !vim9script));
2863+
concat = op == '.' && (*(p + 1) == '.' || in_old_script(2));
28652864
if ((op != '+' && op != '-' && !concat) || p[1] == '='
28662865
|| (p[1] == '.' && p[2] == '='))
28672866
break;
@@ -3402,7 +3401,7 @@ eval7(
34023401

34033402
if (**arg == '.' && (!isdigit(*(*arg + 1))
34043403
#ifdef FEAT_FLOAT
3405-
|| current_sctx.sc_version < 2
3404+
|| in_old_script(2)
34063405
#endif
34073406
))
34083407
{
@@ -5877,7 +5876,7 @@ handle_subscript(
58775876
|| (**arg == '.' && (rettv->v_type == VAR_DICT
58785877
|| (!evaluate
58795878
&& (*arg)[1] != '.'
5880-
&& current_sctx.sc_version >= 2))))
5879+
&& !in_old_script(2)))))
58815880
{
58825881
dict_unref(selfdict);
58835882
if (rettv->v_type == VAR_DICT)

src/evalvars.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ ex_let(exarg_T *eap)
774774
--argend;
775775
expr = skipwhite(argend);
776776
concat = expr[0] == '.'
777-
&& ((expr[1] == '=' && current_sctx.sc_version < 2)
777+
&& ((expr[1] == '=' && in_old_script(2))
778778
|| (expr[1] == '.' && expr[2] == '='));
779779
has_assign = *expr == '=' || (vim_strchr((char_u *)"+-*/%", *expr) != NULL
780780
&& expr[1] == '=');
@@ -2932,7 +2932,7 @@ find_var_ht(char_u *name, char_u **varname)
29322932

29332933
// "version" is "v:version" in all scopes if scriptversion < 3.
29342934
// Same for a few other variables marked with VV_COMPAT.
2935-
if (current_sctx.sc_version < 3)
2935+
if (in_old_script(3))
29362936
{
29372937
hi = hash_find(&compat_hashtab, name);
29382938
if (!HASHITEM_EMPTY(hi))

src/ex_docmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,7 @@ parse_command_modifiers(
29512951
if (ends_excmd2(p, eap->cmd))
29522952
{
29532953
*errormsg =
2954-
_(e_vim9cmd_must_be_followed_by_command);
2954+
_(e_legacy_must_be_followed_by_command);
29552955
return FAIL;
29562956
}
29572957
cmod->cmod_flags |= CMOD_LEGACY;

src/proto/vim9script.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* vim9script.c */
22
int in_vim9script(void);
3+
int in_old_script(int max_version);
34
int current_script_is_vim9(void);
45
void ex_vim9script(exarg_T *eap);
56
int not_in_vim9(exarg_T *eap);

src/testdir/test_vim9_cmd.vim

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,25 @@ def Test_vim9cmd()
1313
vim9cm assert_equal('yes', y)
1414
END
1515
CheckScriptSuccess(lines)
16+
1617
assert_fails('vim9cmd', 'E1164:')
18+
assert_fails('legacy', 'E1234:')
1719
assert_fails('vim9cmd echo "con" . "cat"', 'E15:')
1820

21+
lines =<< trim END
22+
let str = 'con'
23+
vim9cmd str .= 'cat'
24+
END
25+
CheckScriptFailure(lines, 'E492:')
26+
27+
lines =<< trim END
28+
vim9script
29+
legacy echo "con" . "cat"
30+
legacy let str = 'con'
31+
legacy let str .= 'cat'
32+
END
33+
CheckScriptSuccess(lines)
34+
1935
lines =<< trim END
2036
vim9script
2137
def Foo()
@@ -24,11 +40,47 @@ def Test_vim9cmd()
2440
nmap ,; :vim9cmd <SID>Foo()<CR>
2541
END
2642
CheckScriptSuccess(lines)
43+
2744
feedkeys(',;', 'xt')
2845
assert_equal("bar", g:found_bar)
29-
3046
nunmap ,;
3147
unlet g:found_bar
48+
49+
lines =<< trim END
50+
vim9script
51+
legacy echo 1'000
52+
END
53+
CheckScriptFailure(lines, 'E115:')
54+
55+
if has('float')
56+
lines =<< trim END
57+
vim9script
58+
echo .10
59+
END
60+
CheckScriptSuccess(lines)
61+
lines =<< trim END
62+
vim9cmd echo .10
63+
END
64+
CheckScriptSuccess(lines)
65+
lines =<< trim END
66+
vim9script
67+
legacy echo .10
68+
END
69+
CheckScriptFailure(lines, 'E15:')
70+
endif
71+
72+
echo v:version
73+
assert_fails('vim9cmd echo version', 'E121:')
74+
lines =<< trim END
75+
vim9script
76+
echo version
77+
END
78+
CheckScriptFailure(lines, 'E121:')
79+
lines =<< trim END
80+
vim9script
81+
legacy echo version
82+
END
83+
CheckScriptSuccess(lines)
3284
enddef
3385

3486
def Test_edit_wildcards()

src/typval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ eval_number(
17041704
int want_string UNUSED)
17051705
{
17061706
int len;
1707-
int skip_quotes = current_sctx.sc_version >= 4 || in_vim9script();
1707+
int skip_quotes = !in_old_script(4);
17081708
#ifdef FEAT_FLOAT
17091709
char_u *p;
17101710
int get_float = FALSE;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3347,
758760
/**/
759761
3346,
760762
/**/

src/vim9script.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ in_vim9script(void)
3333
}
3434

3535
#if defined(FEAT_EVAL) || defined(PROTO)
36+
/*
37+
* Return TRUE when currently in a script with script version smaller than
38+
* "max_version" or command modifiers forced it.
39+
*/
40+
int
41+
in_old_script(int max_version)
42+
{
43+
return (current_sctx.sc_version <= max_version
44+
&& !(cmdmod.cmod_flags & CMOD_VIM9CMD))
45+
|| (cmdmod.cmod_flags & CMOD_LEGACY);
46+
}
47+
3648
/*
3749
* Return TRUE if the current script is Vim9 script.
3850
* This also returns TRUE in a legacy function in a Vim9 script.

0 commit comments

Comments
 (0)