summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-06-02 16:47:53 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-02 16:47:53 +0200
commitc3cb1c92a335be818971acd89f631e82aa30ad3f (patch)
tree876f7b5a57548ef6655187a4a3d4108d6dc13865
parent0f37e3561db95b0ef0b636588bbd30297e377384 (diff)
patch 8.2.2926: Vim9: no good error for using :legacy in a :def functionv8.2.2926
Problem: Vim9: no good error for using :legacy in a :def function. Solution: Give an explicit error where :legacy is not working. (closes #8309)
-rw-r--r--src/errors.h2
-rw-r--r--src/testdir/test_vim9_func.vim9
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c21
4 files changed, 34 insertions, 0 deletions
diff --git a/src/errors.h b/src/errors.h
index 00d395baea..00e2d565d0 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -417,3 +417,5 @@ EXTERN char e_failed_to_source_defaults[]
INIT(= N_("E1187: Failed to source defaults.vim"));
EXTERN char e_cannot_open_terminal_from_command_line_window[]
INIT(= N_("E1188: Cannot open a terminal from the command line window"));
+EXTERN char e_cannot_use_legacy_with_command_str[]
+ INIT(= N_("E1189: Cannot use :legacy with this command: %s"));
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 3626cca47a..9f0cd3f895 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -2207,6 +2207,15 @@ def Test_legacy_lambda()
CheckScriptSuccess(lines)
enddef
+def Test_legacy_errors()
+ for cmd in ['if', 'elseif', 'else', 'endif',
+ 'for', 'endfor', 'continue', 'break',
+ 'while', 'endwhile',
+ 'try', 'catch', 'finally', 'endtry']
+ CheckDefFailure(['legacy ' .. cmd .. ' expr'], 'E1189:')
+ endfor
+enddef
+
def DoFilterThis(a: string): list<string>
# closure nested inside another closure using argument
var Filter = (l) => filter(l, (_, v) => stridx(v, a) == 0)
diff --git a/src/version.c b/src/version.c
index 188bb1a880..6761b72d8e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2926,
+/**/
2925,
/**/
2924,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 2ea487de78..5152b61a5f 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -9222,6 +9222,27 @@ compile_def_function(
{
char_u *start = ea.cmd;
+ switch (ea.cmdidx)
+ {
+ case CMD_if:
+ case CMD_elseif:
+ case CMD_else:
+ case CMD_endif:
+ case CMD_for:
+ case CMD_endfor:
+ case CMD_continue:
+ case CMD_break:
+ case CMD_while:
+ case CMD_endwhile:
+ case CMD_try:
+ case CMD_catch:
+ case CMD_finally:
+ case CMD_endtry:
+ semsg(_(e_cannot_use_legacy_with_command_str), ea.cmd);
+ goto erret;
+ default: break;
+ }
+
// ":legacy return expr" needs to be handled differently.
if (checkforcmd(&start, "return", 4))
ea.cmdidx = CMD_return;