0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.1342: Vim9: accidentally using "t" gives a confusing error

Problem:    Vim9: accidentally using "x" gives a confusing error.
Solution:   Disallow using ":t" in Vim9 script. (issue #6399)
This commit is contained in:
Bram Moolenaar
2020-08-01 17:00:03 +02:00
parent 2ec208172c
commit f5a48010ef
6 changed files with 22 additions and 11 deletions

View File

@@ -190,8 +190,8 @@ To intentionally avoid a variable being available later, a block can be used:
An existing variable cannot be assigned to with `:let`, since that implies a An existing variable cannot be assigned to with `:let`, since that implies a
declaration. Global, window, tab, buffer and Vim variables can only be used declaration. Global, window, tab, buffer and Vim variables can only be used
without `:let`, because they are are not really declared, they can also be without `:let`, because they are not really declared, they can also be deleted
deleted with `:unlet`. with `:unlet`.
Variables cannot shadow previously defined variables. Variables cannot shadow previously defined variables.
Variables may shadow Ex commands, rename the variable if needed. Variables may shadow Ex commands, rename the variable if needed.
@@ -352,10 +352,11 @@ No curly braces expansion ~
|curly-braces-names| cannot be used. |curly-braces-names| cannot be used.
No :xit, :append, :change or :insert ~ No :xit, :t, :append, :change or :insert ~
These commands are too easily confused with local variable names. Instead of These commands are too easily confused with local variable names.
`:x` or `:xit` you can use `:exit`. Instead of `:x` or `:xit` you can use `:exit`.
Instead of `:t` you can use `:copy`.
Comparators ~ Comparators ~

View File

@@ -7276,6 +7276,9 @@ ex_copymove(exarg_T *eap)
{ {
long n; long n;
if (not_in_vim9(eap) == FAIL)
return;
n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, FALSE, 1); n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, FALSE, 1);
if (eap->arg == NULL) // error detected if (eap->arg == NULL) // error detected
{ {

View File

@@ -1628,18 +1628,21 @@ def Test_fixed_size_list()
enddef enddef
def Test_no_insert_xit() def Test_no_insert_xit()
call CheckDefExecFailure(['x = 1'], 'E1100:')
call CheckDefExecFailure(['a = 1'], 'E1100:') call CheckDefExecFailure(['a = 1'], 'E1100:')
call CheckDefExecFailure(['i = 1'], 'E1100:')
call CheckDefExecFailure(['c = 1'], 'E1100:') call CheckDefExecFailure(['c = 1'], 'E1100:')
call CheckDefExecFailure(['i = 1'], 'E1100:')
call CheckDefExecFailure(['t = 1'], 'E1100:')
call CheckDefExecFailure(['x = 1'], 'E1100:')
CheckScriptFailure(['vim9script', 'x = 1'], 'E1100:')
CheckScriptFailure(['vim9script', 'a = 1'], 'E488:') CheckScriptFailure(['vim9script', 'a = 1'], 'E488:')
CheckScriptFailure(['vim9script', 'a'], 'E1100:') CheckScriptFailure(['vim9script', 'a'], 'E1100:')
CheckScriptFailure(['vim9script', 'i = 1'], 'E488:')
CheckScriptFailure(['vim9script', 'i'], 'E1100:')
CheckScriptFailure(['vim9script', 'c = 1'], 'E488:') CheckScriptFailure(['vim9script', 'c = 1'], 'E488:')
CheckScriptFailure(['vim9script', 'c'], 'E1100:') CheckScriptFailure(['vim9script', 'c'], 'E1100:')
CheckScriptFailure(['vim9script', 'i = 1'], 'E488:')
CheckScriptFailure(['vim9script', 'i'], 'E1100:')
CheckScriptFailure(['vim9script', 't'], 'E1100:')
CheckScriptFailure(['vim9script', 't = 1'], 'E1100:')
CheckScriptFailure(['vim9script', 'x = 1'], 'E1100:')
enddef enddef
def IfElse(what: number): string def IfElse(what: number): string

View File

@@ -754,6 +754,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 */
/**/
1342,
/**/ /**/
1341, 1341,
/**/ /**/

View File

@@ -7467,6 +7467,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
case CMD_append: case CMD_append:
case CMD_change: case CMD_change:
case CMD_insert: case CMD_insert:
case CMD_t:
case CMD_xit: case CMD_xit:
not_in_vim9(&ea); not_in_vim9(&ea);
goto erret; goto erret;

View File

@@ -67,9 +67,10 @@ not_in_vim9(exarg_T *eap)
if (in_vim9script()) if (in_vim9script())
switch (eap->cmdidx) switch (eap->cmdidx)
{ {
case CMD_insert:
case CMD_append: case CMD_append:
case CMD_change: case CMD_change:
case CMD_insert:
case CMD_t:
case CMD_xit: case CMD_xit:
semsg(_("E1100: Missing :let: %s"), eap->cmd); semsg(_("E1100: Missing :let: %s"), eap->cmd);
return FAIL; return FAIL;