summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-07-29 21:20:41 +0200
committerBram Moolenaar <Bram@vim.org>2020-07-29 21:20:41 +0200
commit696ba23149eb5a7226e606e3fe6f15fdd064c5f7 (patch)
tree76bcd1a409c844c1e0298581f56098c4b0ba869a /src
parent1040956292a9f2c3d02fc08febd5acf349c85590 (diff)
downloadvim-git-696ba23149eb5a7226e606e3fe6f15fdd064c5f7.tar.gz
patch 8.2.1323: Vim9: invalid operators only rejected in :def functionv8.2.1323
Problem: Vim9: invalid operators only rejected in :def function. Solution: Also reject them at script level. (closes #6564)
Diffstat (limited to 'src')
-rw-r--r--src/eval.c48
-rw-r--r--src/proto/vim9compile.pro1
-rw-r--r--src/testdir/test_vim9_expr.vim26
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c2
5 files changed, 38 insertions, 41 deletions
diff --git a/src/eval.c b/src/eval.c
index 81913c7a3..451bb16b7 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2420,9 +2420,9 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
{
char_u *p;
int getnext;
- int i;
exptype_T type = EXPR_UNKNOWN;
int len = 2;
+ int type_is = FALSE;
/*
* Get the first variable.
@@ -2431,44 +2431,7 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
return FAIL;
p = eval_next_non_blank(*arg, evalarg, &getnext);
- switch (p[0])
- {
- case '=': if (p[1] == '=')
- type = EXPR_EQUAL;
- else if (p[1] == '~')
- type = EXPR_MATCH;
- break;
- case '!': if (p[1] == '=')
- type = EXPR_NEQUAL;
- else if (p[1] == '~')
- type = EXPR_NOMATCH;
- break;
- case '>': if (p[1] != '=')
- {
- type = EXPR_GREATER;
- len = 1;
- }
- else
- type = EXPR_GEQUAL;
- break;
- case '<': if (p[1] != '=')
- {
- type = EXPR_SMALLER;
- len = 1;
- }
- else
- type = EXPR_SEQUAL;
- break;
- case 'i': if (p[1] == 's')
- {
- if (p[2] == 'n' && p[3] == 'o' && p[4] == 't')
- len = 5;
- i = p[len];
- if (!isalnum(i) && i != '_')
- type = len == 2 ? EXPR_IS : EXPR_ISNOT;
- }
- break;
- }
+ type = get_compare_type(p, &len, &type_is);
/*
* If there is a comparative operator, use it.
@@ -2482,6 +2445,13 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
if (getnext)
*arg = eval_next_line(evalarg);
+ if (vim9script && type_is && (p[len] == '?' || p[len] == '#'))
+ {
+ semsg(_(e_invexpr2), p);
+ clear_tv(rettv);
+ return FAIL;
+ }
+
// extra question mark appended: ignore case
if (p[len] == '?')
{
diff --git a/src/proto/vim9compile.pro b/src/proto/vim9compile.pro
index 4108c04af..fd2dd1bf4 100644
--- a/src/proto/vim9compile.pro
+++ b/src/proto/vim9compile.pro
@@ -16,6 +16,7 @@ int vim9_comment_start(char_u *p);
char_u *peek_next_line_from_context(cctx_T *cctx);
char_u *next_line_from_context(cctx_T *cctx, int skip_comment);
char_u *to_name_const_end(char_u *arg);
+exptype_T get_compare_type(char_u *p, int *len, int *type_is);
int assignment_len(char_u *p, int *heredoc);
void vim9_declare_error(char_u *name);
int check_vim9_unlet(char_u *name);
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index e29ef5cf0..550e41982 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -831,7 +831,7 @@ def Test_expr5()
enddef
def Test_expr5_vim9script()
- # only checks line continuation
+ # check line continuation
let lines =<< trim END
vim9script
let var = 11
@@ -848,6 +848,30 @@ def Test_expr5_vim9script()
assert_equal('onetwo', var)
END
CheckScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ echo 'abc' is# 'abc'
+ END
+ CheckScriptFailure(lines, 'E15:')
+
+ lines =<< trim END
+ vim9script
+ echo 'abc' is? 'abc'
+ END
+ CheckScriptFailure(lines, 'E15:')
+
+ lines =<< trim END
+ vim9script
+ echo 'abc' isnot# 'abc'
+ END
+ CheckScriptFailure(lines, 'E15:')
+
+ lines =<< trim END
+ vim9script
+ echo 'abc' isnot? 'abc'
+ END
+ CheckScriptFailure(lines, 'E15:')
enddef
def Test_expr5_float()
diff --git a/src/version.c b/src/version.c
index bb1c4ab41..033f36072 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1323,
+/**/
1322,
/**/
1321,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index f1509048e..cf08e9558 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3633,7 +3633,7 @@ get_vim_constant(char_u **arg, typval_T *rettv)
}
}
- static exptype_T
+ exptype_T
get_compare_type(char_u *p, int *len, int *type_is)
{
exptype_T type = EXPR_UNKNOWN;