diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-06-26 21:28:25 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-06-26 21:28:25 +0200 |
commit | 793648fb563359396a23740c72a6e04cb64df3a9 (patch) | |
tree | 1a60f138bfb8f777aae130e3028ada8057b5f3c4 | |
parent | 5d3c9f8c2a0fc29ba4ac8e0f052378b64d9e3dd3 (diff) |
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"v8.2.1062
Problem: Vim9: no line break allowed inside "cond ? val1 : val2".
Solution: Check for operator after line break.
-rw-r--r-- | src/eval.c | 14 | ||||
-rw-r--r-- | src/testdir/test_vim9_expr.vim | 21 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 35 insertions, 2 deletions
diff --git a/src/eval.c b/src/eval.c index 0402b36385..fe53632df9 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1892,13 +1892,17 @@ eval0( int eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg) { + char_u *p; + int getnext; + /* * Get the first variable. */ if (eval2(arg, rettv, evalarg) == FAIL) return FAIL; - if ((*arg)[0] == '?') + p = eval_next_non_blank(*arg, evalarg, &getnext); + if (*p == '?') { int result; typval_T var2; @@ -1906,6 +1910,9 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg) int orig_flags; int evaluate; + if (getnext) + *arg = eval_next_line(evalarg); + if (evalarg == NULL) { CLEAR_FIELD(nested_evalarg); @@ -1942,13 +1949,16 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg) /* * Check for the ":". */ - if ((*arg)[0] != ':') + p = eval_next_non_blank(*arg, evalarg, &getnext); + if (*p != ':') { emsg(_(e_missing_colon)); if (evaluate && result) clear_tv(rettv); return FAIL; } + if (getnext) + *arg = eval_next_line(evalarg); /* * Get the third variable. Recursive! diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim index b37f92fb6a..566af673ff 100644 --- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -45,6 +45,27 @@ def Test_expr1() assert_equal(function('len'), RetThat) enddef +def Test_expr1_vimscript() + " only checks line continuation + let lines =<< trim END + vim9script + let var = 1 + ? 'yes' + : 'no' + assert_equal('yes', var) + END + CheckScriptSuccess(lines) + + lines =<< trim END + vim9script + let var = v:false + ? 'yes' + : 'no' + assert_equal('no', var) + END + CheckScriptSuccess(lines) +enddef + func Test_expr1_fails() call CheckDefFailure(["let x = 1 ? 'one'"], "Missing ':' after '?'") call CheckDefFailure(["let x = 1 ? 'one' : xxx"], "E1001:") diff --git a/src/version.c b/src/version.c index aef2fe9e97..a97b40acef 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 */ /**/ + 1062, +/**/ 1061, /**/ 1060, |