Skip to content

Commit f5a4801

Browse files
committed
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)
1 parent 2ec2081 commit f5a4801

6 files changed

Lines changed: 22 additions & 11 deletions

File tree

runtime/doc/vim9.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ To intentionally avoid a variable being available later, a block can be used:
190190
191191
An existing variable cannot be assigned to with `:let`, since that implies a
192192
declaration. Global, window, tab, buffer and Vim variables can only be used
193-
without `:let`, because they are are not really declared, they can also be
194-
deleted with `:unlet`.
193+
without `:let`, because they are not really declared, they can also be deleted
194+
with `:unlet`.
195195

196196
Variables cannot shadow previously defined variables.
197197
Variables may shadow Ex commands, rename the variable if needed.
@@ -352,10 +352,11 @@ No curly braces expansion ~
352352
|curly-braces-names| cannot be used.
353353

354354

355-
No :xit, :append, :change or :insert ~
355+
No :xit, :t, :append, :change or :insert ~
356356

357-
These commands are too easily confused with local variable names. Instead of
358-
`:x` or `:xit` you can use `:exit`.
357+
These commands are too easily confused with local variable names.
358+
Instead of `:x` or `:xit` you can use `:exit`.
359+
Instead of `:t` you can use `:copy`.
359360

360361

361362
Comparators ~

src/ex_docmd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7276,6 +7276,9 @@ ex_copymove(exarg_T *eap)
72767276
{
72777277
long n;
72787278

7279+
if (not_in_vim9(eap) == FAIL)
7280+
return;
7281+
72797282
n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, FALSE, 1);
72807283
if (eap->arg == NULL) // error detected
72817284
{

src/testdir/test_vim9_script.vim

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,18 +1628,21 @@ def Test_fixed_size_list()
16281628
enddef
16291629

16301630
def Test_no_insert_xit()
1631-
call CheckDefExecFailure(['x = 1'], 'E1100:')
16321631
call CheckDefExecFailure(['a = 1'], 'E1100:')
1633-
call CheckDefExecFailure(['i = 1'], 'E1100:')
16341632
call CheckDefExecFailure(['c = 1'], 'E1100:')
1633+
call CheckDefExecFailure(['i = 1'], 'E1100:')
1634+
call CheckDefExecFailure(['t = 1'], 'E1100:')
1635+
call CheckDefExecFailure(['x = 1'], 'E1100:')
16351636

1636-
CheckScriptFailure(['vim9script', 'x = 1'], 'E1100:')
16371637
CheckScriptFailure(['vim9script', 'a = 1'], 'E488:')
16381638
CheckScriptFailure(['vim9script', 'a'], 'E1100:')
1639-
CheckScriptFailure(['vim9script', 'i = 1'], 'E488:')
1640-
CheckScriptFailure(['vim9script', 'i'], 'E1100:')
16411639
CheckScriptFailure(['vim9script', 'c = 1'], 'E488:')
16421640
CheckScriptFailure(['vim9script', 'c'], 'E1100:')
1641+
CheckScriptFailure(['vim9script', 'i = 1'], 'E488:')
1642+
CheckScriptFailure(['vim9script', 'i'], 'E1100:')
1643+
CheckScriptFailure(['vim9script', 't'], 'E1100:')
1644+
CheckScriptFailure(['vim9script', 't = 1'], 'E1100:')
1645+
CheckScriptFailure(['vim9script', 'x = 1'], 'E1100:')
16431646
enddef
16441647

16451648
def IfElse(what: number): string

src/version.c

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

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1342,
757759
/**/
758760
1341,
759761
/**/

src/vim9compile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7467,6 +7467,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
74677467
case CMD_append:
74687468
case CMD_change:
74697469
case CMD_insert:
7470+
case CMD_t:
74707471
case CMD_xit:
74717472
not_in_vim9(&ea);
74727473
goto erret;

src/vim9script.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ not_in_vim9(exarg_T *eap)
6767
if (in_vim9script())
6868
switch (eap->cmdidx)
6969
{
70-
case CMD_insert:
7170
case CMD_append:
7271
case CMD_change:
72+
case CMD_insert:
73+
case CMD_t:
7374
case CMD_xit:
7475
semsg(_("E1100: Missing :let: %s"), eap->cmd);
7576
return FAIL;

0 commit comments

Comments
 (0)