]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2" v8.2.1062
authorBram Moolenaar <Bram@vim.org>
Fri, 26 Jun 2020 19:28:25 +0000 (21:28 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 26 Jun 2020 19:28:25 +0000 (21:28 +0200)
Problem:    Vim9: no line break allowed inside "cond ? val1 : val2".
Solution:   Check for operator after line break.

src/eval.c
src/testdir/test_vim9_expr.vim
src/version.c

index 0402b36385adb20a3ec44270e339e3360a8b328a..fe53632df9eba668003a28d5882e823c0c9c72b5 100644 (file)
@@ -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!
index b37f92fb6a6340c633b1e7b81e15709ce42c255f..566af673ff7a76d53be4ec2030940f12cdf9f7b8 100644 (file)
@@ -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:")
index aef2fe9e97cd9774154db79d55efaa7e201d5020..a97b40acef10ba2c895ba73dcf5744ce5c5c0e02 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1062,
 /**/
     1061,
 /**/