Skip to content

Commit

Permalink
patch 8.2.3058: Vim9: cannot use ternary operator in parenthesis
Browse files Browse the repository at this point in the history
Problem:    Vim9: cannot use ternary operator in parenthesis.
Solution:   Do not use "==" for a default argument value.  (closes #8462)
  • Loading branch information
brammool committed Jun 26, 2021
1 parent 307dec4 commit 015cf10
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/testdir/test_vim9_func.vim
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/userfunc.c
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -755,6 +755,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3058,
/**/
3057,
/**/
Expand Down

0 comments on commit 015cf10

Please sign in to comment.