Problem: Vim9: no error for missing white space around operator.
Solution: Check for white space. (closes #6618)
int getnext;
char_u *p;
int op;
+ int oplen;
int concat;
typval_T var2;
if (op != '+' && op != '-' && !concat)
break;
+ evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
if (getnext)
*arg = eval_next_line(evalarg);
else
+ {
+ if (evaluate && in_vim9script() && !VIM_ISWHITE(**arg))
+ {
+ error_white_both(p, 1);
+ clear_tv(rettv);
+ return FAIL;
+ }
*arg = p;
- evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
+ }
if ((op != '+' || (rettv->v_type != VAR_LIST
&& rettv->v_type != VAR_BLOB))
#ifdef FEAT_FLOAT
/*
* Get the second variable.
*/
- if (op == '.' && *(*arg + 1) == '.') // .. string concatenation
- ++*arg;
- *arg = skipwhite_and_linebreak(*arg + 1, evalarg);
+ oplen = (op == '.' && *(*arg + 1) == '.') ? 2 : 1;
+ if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[oplen]))
+ {
+ error_white_both(p, oplen);
+ clear_tv(rettv);
+ return FAIL;
+ }
+ *arg = skipwhite_and_linebreak(*arg + oplen, evalarg);
if (eval6(arg, &var2, evalarg, op == '.') == FAIL)
{
clear_tv(rettv);
}
else
{
+ *arg = skipwhite(*arg);
if (**arg != '(')
{
if (verbose)
/*
* Get the length of the name of a function or internal variable.
- * "arg" is advanced to the first non-white character after the name.
+ * "arg" is advanced to after the name.
* Return 0 if something is wrong.
*/
int
return 0;
len = (int)(p - *arg);
- *arg = skipwhite(p);
+ *arg = p;
return len;
}
}
else
{
+ arg = skipwhite(arg);
if (tofree != NULL)
name = tofree;
if (eval_variable(name, len, &tv, NULL, TRUE, FALSE) == FAIL)
int
var_exists(char_u *var)
{
+ char_u *arg = var;
char_u *name;
char_u *tofree;
typval_T tv;
// get_name_len() takes care of expanding curly braces
name = var;
- len = get_name_len(&var, &tofree, TRUE, FALSE);
+ len = get_name_len(&arg, &tofree, TRUE, FALSE);
if (len > 0)
{
if (tofree != NULL)
if (n)
{
// handle d.key, l[idx], f(expr)
- n = (handle_subscript(&var, &tv, &EVALARG_EVALUATE, FALSE) == OK);
+ arg = skipwhite(arg);
+ n = (handle_subscript(&arg, &tv, &EVALARG_EVALUATE, FALSE) == OK);
if (n)
clear_tv(&tv);
}
}
- if (*var != NUL)
+ if (*arg != NUL)
n = FALSE;
vim_free(tofree);
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);
+void error_white_both(char_u *op, int len);
int assignment_len(char_u *p, int *heredoc);
void vim9_declare_error(char_u *name);
int check_vim9_unlet(char_u *name);
echo 'abc' isnot? 'abc'
END
CheckScriptFailure(lines, 'E15:')
+
+ # check white space
+ lines =<< trim END
+ vim9script
+ echo 5+6
+ END
+ CheckScriptFailure(lines, 'E1004:')
+ lines =<< trim END
+ vim9script
+ echo 5 +6
+ END
+ CheckScriptFailure(lines, 'E1004:')
+ lines =<< trim END
+ vim9script
+ echo 5+ 6
+ END
+ CheckScriptFailure(lines, 'E1004:')
+
+ lines =<< trim END
+ vim9script
+ echo 'a'..'b'
+ END
+ CheckScriptFailure(lines, 'E1004:')
+ lines =<< trim END
+ vim9script
+ echo 'a' ..'b'
+ END
+ CheckScriptFailure(lines, 'E1004:')
+ lines =<< trim END
+ vim9script
+ echo 'a'.. 'b'
+ END
+ CheckScriptFailure(lines, 'E1004:')
enddef
def Test_expr5_float()
def TreeWalk(dir: string): list<any>
return readdir(dir)->map({_, val ->
fnamemodify(dir .. '/' .. val, ':p')->isdirectory()
- ? {val : TreeWalk(dir .. '/' .. val)}
+ ? {val: TreeWalk(dir .. '/' .. val)}
: val
})
enddef
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1365,
/**/
1364,
/**/
return OK;
}
+/*
+ * Give the "white on both sides" error, taking the operator from "p[len]".
+ */
+ void
+error_white_both(char_u *op, int len)
+{
+ char_u buf[10];
+
+ vim_strncpy(buf, op, len);
+ semsg(_(e_white_both), buf);
+}
+
/*
* * number multiplication
* / number division
if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[1]))
{
- char_u buf[3];
-
- vim_strncpy(buf, op, 1);
- semsg(_(e_white_both), buf);
+ error_white_both(op, 1);
return FAIL;
}
*arg = skipwhite(op + 1);
if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[oplen]))
{
- char_u buf[3];
-
- vim_strncpy(buf, op, oplen);
- semsg(_(e_white_both), buf);
+ error_white_both(op, oplen);
return FAIL;
}
if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[len]))
{
- char_u buf[7];
-
- vim_strncpy(buf, p, len);
- semsg(_(e_white_both), buf);
+ error_white_both(p, len);
return FAIL;
}
if (oplen > 0 && (!VIM_ISWHITE(*sp) || !VIM_ISWHITE(op[oplen])))
{
- char_u buf[4];
-
- vim_strncpy(buf, op, oplen);
- semsg(_(e_white_both), buf);
+ error_white_both(op, oplen);
return NULL;
}