diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-06-26 21:52:02 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-06-26 21:52:02 +0200 |
commit | 015cf103115f9a0380ae3e3e85a77792cfe87d49 (patch) | |
tree | f92897f4d2040558626d1f14d1b8dd354ba53d97 | |
parent | 307dec4567e0f64a7a4cfc2d5302d2aba26db775 (diff) | |
download | vim-git-015cf103115f9a0380ae3e3e85a77792cfe87d49.tar.gz |
patch 8.2.3058: Vim9: cannot use ternary operator in parenthesisv8.2.3058
Problem: Vim9: cannot use ternary operator in parenthesis.
Solution: Do not use "==" for a default argument value. (closes #8462)
-rw-r--r-- | src/testdir/test_vim9_func.vim | 7 | ||||
-rw-r--r-- | src/userfunc.c | 7 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 15 insertions, 1 deletions
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim index ee97e56ea..563b7bab8 100644 --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -924,6 +924,13 @@ def Test_call_lambda_args() 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 var l = [1, 2, 3] diff --git a/src/userfunc.c b/src/userfunc.c index cedd37b9a..3321f089c 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -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; diff --git a/src/version.c b/src/version.c index 6069a397b..59f84d446 100644 --- a/src/version.c +++ b/src/version.c @@ -756,6 +756,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3058, +/**/ 3057, /**/ 3056, |