Mercurial > vim
changeset 21634:3a86e41fdffd v8.2.1367
patch 8.2.1367: Vim9: no error for missing white space around operator
Commit: https://github.com/vim/vim/commit/b4caa163ff7bfacd4bec00e4baa55b5669ff1191
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Aug 5 11:36:52 2020 +0200
patch 8.2.1367: Vim9: no error for missing white space around operator
Problem: Vim9: no error for missing white space around operator.
Solution: Check for white space around *, / and %.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 05 Aug 2020 11:45:04 +0200 |
parents | e7d7508f78bb |
children | 20af1fd0ef58 |
files | src/eval.c src/testdir/test_vim9_expr.vim src/version.c |
diffstat | 3 files changed, 56 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -2586,13 +2586,14 @@ eval5(char_u **arg, typval_T *rettv, eva break; evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE); + oplen = (concat && p[1] == '.') ? 2 : 1; if (getnext) *arg = eval_next_line(evalarg); else { if (evaluate && in_vim9script() && !VIM_ISWHITE(**arg)) { - error_white_both(p, 1); + error_white_both(p, oplen); clear_tv(rettv); return FAIL; } @@ -2622,7 +2623,6 @@ eval5(char_u **arg, typval_T *rettv, eva /* * 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); @@ -2796,17 +2796,25 @@ eval6( if (op != '*' && op != '/' && op != '%') 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; + } #ifdef FEAT_FLOAT f1 = 0; f2 = 0; #endif error = FALSE; - evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE); if (evaluate) { #ifdef FEAT_FLOAT @@ -2829,7 +2837,13 @@ eval6( /* * Get the second variable. */ - *arg = skipwhite(*arg + 1); + if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[1])) + { + error_white_both(p, 1); + clear_tv(rettv); + return FAIL; + } + *arg = skipwhite_and_linebreak(*arg + 1, evalarg); if (eval7(arg, &var2, evalarg, FALSE) == FAIL) return FAIL;
--- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -843,6 +843,15 @@ def Test_expr5_vim9script() lines =<< trim END vim9script + let var = 11 + + 77 - + 22 + assert_equal(66, var) + END + CheckScriptSuccess(lines) + + lines =<< trim END + vim9script let var = 'one' .. 'two' assert_equal('onetwo', var) @@ -999,7 +1008,7 @@ def Test_expr6() enddef def Test_expr6_vim9script() - # only checks line continuation + # check line continuation let lines =<< trim END vim9script let var = 11 @@ -1016,6 +1025,32 @@ def Test_expr6_vim9script() assert_equal(5, var) END CheckScriptSuccess(lines) + + lines =<< trim END + vim9script + let var = 11 * + 22 / + 3 + assert_equal(80, var) + END + CheckScriptSuccess(lines) + + # 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:') enddef def Test_expr6_float()