]> granicus.if.org Git - vim/commitdiff
patch 8.2.3058: Vim9: cannot use ternary operator in parenthesis v8.2.3058
authorBram Moolenaar <Bram@vim.org>
Sat, 26 Jun 2021 19:52:02 +0000 (21:52 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 26 Jun 2021 19:52:02 +0000 (21:52 +0200)
Problem:    Vim9: cannot use ternary operator in parenthesis.
Solution:   Do not use "==" for a default argument value.  (closes #8462)

src/testdir/test_vim9_func.vim
src/userfunc.c
src/version.c

index ee97e56ea682183215d5f00046b45fa5a9011210..563b7bab8ca57a9498800ec8e5ad699dab11557d 100644 (file)
@@ -923,6 +923,13 @@ def Test_call_lambda_args()
   END
   CheckDefAndScriptFailure(lines, 'E1172:')
 
+  lines =<< trim END
+      var a = 0
+      var b = (a == 0 ? 1 : 2)
+      assert_equal(1, b)
+  END
+  CheckDefAndScriptSuccess(lines)
+
   lines =<< trim END
       def ShadowLocal()
         var one = 1
index cedd37b9a0faaa51ec5deb023e755fd32fa1c741..3321f089c0ab26a365bfc1b769ba551835df547f 100644 (file)
@@ -266,13 +266,18 @@ get_function_args(
        }
        else
        {
+           char_u *np;
+
            arg = p;
            p = one_function_arg(p, newargs, argtypes, types_optional,
                                                         evalarg, FALSE, skip);
            if (p == arg)
                break;
 
-           if (*skipwhite(p) == '=' && default_args != NULL)
+           // Recognize " = expr" but not " == expr".  A lambda can have
+           // "(a = expr" but "(a == expr" is not a lambda.
+           np = skipwhite(p);
+           if (*np == '=' && np[1] != '=' && default_args != NULL)
            {
                typval_T        rettv;
 
index 6069a397b12be497605f15e79254c8ac78202eca..59f84d446b9ccfdfbee9df582cd29e81821b32d1 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3058,
 /**/
     3057,
 /**/