Problem: Vim9: invalid operators only rejected in :def function.
Solution: Also reject them at script level. (closes #6564)
{
char_u *p;
int getnext;
- int i;
exptype_T type = EXPR_UNKNOWN;
int len = 2;
+ int type_is = FALSE;
/*
* Get the first variable.
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.
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] == '?')
{
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);
enddef
def Test_expr5_vim9script()
- # only checks line continuation
+ # check line continuation
let lines =<< trim END
vim9script
let var = 11
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()
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1323,
/**/
1322,
/**/
}
}
- static exptype_T
+ exptype_T
get_compare_type(char_u *p, int *len, int *type_is)
{
exptype_T type = EXPR_UNKNOWN;