Skip to content

Commit 4799cef

Browse files
committed
patch 8.2.3376: Vim9: no warning that "@r" does not do anything
Problem: Vim9: no warning that "@r" does not do anything. Solution: Give a "no effect" error. (closes #8779)
1 parent df9070e commit 4799cef

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

src/ex_eval.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,26 @@ report_discard_pending(int pending, void *value)
887887
}
888888
}
889889

890+
int
891+
cmd_is_name_only(char_u *arg)
892+
{
893+
char_u *p = arg;
894+
char_u *alias;
895+
int name_only = FALSE;
896+
897+
if (*p == '&')
898+
{
899+
++p;
900+
if (STRNCMP("l:", p, 2) == 0 || STRNCMP("g:", p, 2) == 0)
901+
p += 2;
902+
}
903+
else if (*p == '@')
904+
++p;
905+
get_name_len(&p, &alias, FALSE, FALSE);
906+
name_only = ends_excmd2(arg, skipwhite(p));
907+
vim_free(alias);
908+
return name_only;
909+
}
890910

891911
/*
892912
* ":eval".
@@ -897,18 +917,10 @@ ex_eval(exarg_T *eap)
897917
typval_T tv;
898918
evalarg_T evalarg;
899919
int name_only = FALSE;
900-
char_u *p;
901920
long lnum = SOURCING_LNUM;
902921

903922
if (in_vim9script())
904-
{
905-
char_u *alias;
906-
907-
p = eap->arg;
908-
get_name_len(&p, &alias, FALSE, FALSE);
909-
name_only = ends_excmd2(eap->arg, skipwhite(p));
910-
vim_free(alias);
911-
}
923+
name_only = cmd_is_name_only(eap->arg);
912924

913925
fill_evalarg_from_eap(&evalarg, eap, eap->skip);
914926

src/proto/ex_eval.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int throw_exception(void *value, except_type_T type, char_u *cmdname);
1212
void discard_current_exception(void);
1313
void catch_exception(except_T *excp);
1414
void report_make_pending(int pending, void *value);
15+
int cmd_is_name_only(char_u *arg);
1516
void ex_eval(exarg_T *eap);
1617
void ex_if(exarg_T *eap);
1718
void ex_endif(exarg_T *eap);

src/testdir/test_vim9_cmd.vim

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def Test_option_use_linebreak()
537537
CheckDefAndScriptSuccess(lines)
538538
enddef
539539

540-
def Test_register_use_linebreak()
540+
def Test_use_register()
541541
var lines =<< trim END
542542
new
543543
@a = 'one'
@@ -551,6 +551,12 @@ def Test_register_use_linebreak()
551551
bwipe!
552552
END
553553
CheckDefAndScriptSuccess(lines)
554+
555+
lines =<< trim END
556+
@a = 'echo "text"'
557+
@a
558+
END
559+
CheckDefAndScriptFailure(lines, 'E1207:')
554560
enddef
555561

556562
def Test_environment_use_linebreak()

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+
3376,
758760
/**/
759761
3375,
760762
/**/

src/vim9compile.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8828,17 +8828,13 @@ compile_eval(char_u *arg, cctx_T *cctx)
88288828
{
88298829
char_u *p = arg;
88308830
int name_only;
8831-
char_u *alias;
88328831
long lnum = SOURCING_LNUM;
88338832

88348833
// find_ex_command() will consider a variable name an expression, assuming
88358834
// that something follows on the next line. Check that something actually
88368835
// follows, otherwise it's probably a misplaced command.
8837-
get_name_len(&p, &alias, FALSE, FALSE);
8838-
name_only = ends_excmd2(arg, skipwhite(p));
8839-
vim_free(alias);
8836+
name_only = cmd_is_name_only(arg);
88408837

8841-
p = arg;
88428838
if (compile_expr0(&p, cctx) == FAIL)
88438839
return NULL;
88448840

0 commit comments

Comments
 (0)