To: vim_dev@googlegroups.com Subject: Patch 8.2.1365 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1365 Problem: Vim9: no error for missing white space around operator. Solution: Check for white space. (closes #6618) Files: src/eval.c, src/vim9compile.c, src/proto/vim9compile.pro, src/evalvars.c, src/testdir/test_vim9_expr.vim, src/testdir/test_vim9_func.vim *** ../vim-8.2.1364/src/eval.c 2020-08-04 15:52:58.281452992 +0200 --- src/eval.c 2020-08-04 23:06:34.991516468 +0200 *************** *** 2574,2579 **** --- 2574,2580 ---- int getnext; char_u *p; int op; + int oplen; int concat; typval_T var2; *************** *** 2584,2594 **** if (op != '+' && op != '-' && !concat) break; if (getnext) *arg = eval_next_line(evalarg); else *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 --- 2585,2603 ---- 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; ! } if ((op != '+' || (rettv->v_type != VAR_LIST && rettv->v_type != VAR_BLOB)) #ifdef FEAT_FLOAT *************** *** 2613,2621 **** /* * Get the second variable. */ ! if (op == '.' && *(*arg + 1) == '.') // .. string concatenation ! ++*arg; ! *arg = skipwhite_and_linebreak(*arg + 1, evalarg); if (eval6(arg, &var2, evalarg, op == '.') == FAIL) { clear_tv(rettv); --- 2622,2635 ---- /* * Get the second variable. */ ! 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); *************** *** 3358,3363 **** --- 3372,3378 ---- } else { + *arg = skipwhite(*arg); if (**arg != '(') { if (verbose) *************** *** 4841,4847 **** /* * Get the length of the name of a function or internal variable. ! * "arg" is advanced to the first non-white character after the name. * Return 0 if something is wrong. */ int --- 4856,4862 ---- /* * Get the length of the name of a function or internal variable. ! * "arg" is advanced to after the name. * Return 0 if something is wrong. */ int *************** *** 4867,4873 **** return 0; len = (int)(p - *arg); ! *arg = skipwhite(p); return len; } --- 4882,4888 ---- return 0; len = (int)(p - *arg); ! *arg = p; return len; } *** ../vim-8.2.1364/src/vim9compile.c 2020-08-02 18:58:50.465504251 +0200 --- src/vim9compile.c 2020-08-04 22:38:16.156297785 +0200 *************** *** 4244,4249 **** --- 4244,4261 ---- } /* + * 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 * % number modulo *************** *** 4275,4284 **** 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); return FAIL; } *arg = skipwhite(op + 1); --- 4287,4293 ---- if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[1])) { ! error_white_both(op, 1); return FAIL; } *arg = skipwhite(op + 1); *************** *** 4354,4363 **** 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); return FAIL; } --- 4363,4369 ---- if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[oplen])) { ! error_white_both(op, oplen); return FAIL; } *************** *** 4486,4495 **** 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); return FAIL; } --- 4492,4498 ---- if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[len])) { ! error_white_both(p, len); return FAIL; } *************** *** 5132,5141 **** if (oplen > 0 && (!VIM_ISWHITE(*sp) || !VIM_ISWHITE(op[oplen]))) { ! char_u buf[4]; ! ! vim_strncpy(buf, op, oplen); ! semsg(_(e_white_both), buf); return NULL; } --- 5135,5141 ---- if (oplen > 0 && (!VIM_ISWHITE(*sp) || !VIM_ISWHITE(op[oplen]))) { ! error_white_both(op, oplen); return NULL; } *** ../vim-8.2.1364/src/proto/vim9compile.pro 2020-07-29 21:20:37.926626437 +0200 --- src/proto/vim9compile.pro 2020-08-04 22:35:13.564665955 +0200 *************** *** 17,22 **** --- 17,23 ---- 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); *** ../vim-8.2.1364/src/evalvars.c 2020-08-02 16:58:55.763760810 +0200 --- src/evalvars.c 2020-08-04 23:09:25.579081607 +0200 *************** *** 1137,1142 **** --- 1137,1143 ---- } else { + arg = skipwhite(arg); if (tofree != NULL) name = tofree; if (eval_variable(name, len, &tv, NULL, TRUE, FALSE) == FAIL) *************** *** 3358,3363 **** --- 3359,3365 ---- int var_exists(char_u *var) { + char_u *arg = var; char_u *name; char_u *tofree; typval_T tv; *************** *** 3366,3372 **** // get_name_len() takes care of expanding curly braces name = var; ! len = get_name_len(&var, &tofree, TRUE, FALSE); if (len > 0) { if (tofree != NULL) --- 3368,3374 ---- // get_name_len() takes care of expanding curly braces name = var; ! len = get_name_len(&arg, &tofree, TRUE, FALSE); if (len > 0) { if (tofree != NULL) *************** *** 3375,3386 **** if (n) { // handle d.key, l[idx], f(expr) ! n = (handle_subscript(&var, &tv, &EVALARG_EVALUATE, FALSE) == OK); if (n) clear_tv(&tv); } } ! if (*var != NUL) n = FALSE; vim_free(tofree); --- 3377,3389 ---- if (n) { // handle d.key, l[idx], f(expr) ! arg = skipwhite(arg); ! n = (handle_subscript(&arg, &tv, &EVALARG_EVALUATE, FALSE) == OK); if (n) clear_tv(&tv); } } ! if (*arg != NUL) n = FALSE; vim_free(tofree); *** ../vim-8.2.1364/src/testdir/test_vim9_expr.vim 2020-08-02 18:58:50.465504251 +0200 --- src/testdir/test_vim9_expr.vim 2020-08-04 22:41:51.495790616 +0200 *************** *** 872,877 **** --- 872,910 ---- 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() *** ../vim-8.2.1364/src/testdir/test_vim9_func.vim 2020-08-01 23:22:15.192256533 +0200 --- src/testdir/test_vim9_func.vim 2020-08-04 23:22:08.625024678 +0200 *************** *** 1270,1276 **** def TreeWalk(dir: string): list return readdir(dir)->map({_, val -> fnamemodify(dir .. '/' .. val, ':p')->isdirectory() ! ? {val : TreeWalk(dir .. '/' .. val)} : val }) enddef --- 1270,1276 ---- def TreeWalk(dir: string): list return readdir(dir)->map({_, val -> fnamemodify(dir .. '/' .. val, ':p')->isdirectory() ! ? {val: TreeWalk(dir .. '/' .. val)} : val }) enddef *** ../vim-8.2.1364/src/version.c 2020-08-04 21:46:15.366707429 +0200 --- src/version.c 2020-08-04 22:33:27.980843240 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1365, /**/ -- ~ ~ ~ ".signature" 4 lines, 50 characters written /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///