0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.1851: Vim9: "!" followed by space incorrectly used

Problem:    Vim9: "!" followed by space incorrectly used.
Solution:   Skip over trailing spaces. (closes #7131)
This commit is contained in:
Bram Moolenaar 2020-10-15 21:54:56 +02:00
parent a604ccc959
commit 27491cd3ef
4 changed files with 28 additions and 6 deletions

View File

@ -3390,10 +3390,14 @@ eval7_leader(
f = rettv->vval.v_float; f = rettv->vval.v_float;
else else
#endif #endif
{
while (VIM_ISWHITE(end_leader[-1]))
--end_leader;
if (in_vim9script() && end_leader[-1] == '!') if (in_vim9script() && end_leader[-1] == '!')
val = tv2bool(rettv); val = tv2bool(rettv);
else else
val = tv_get_number_chk(rettv, &error); val = tv_get_number_chk(rettv, &error);
}
if (error) if (error)
{ {
clear_tv(rettv); clear_tv(rettv);

View File

@ -2292,6 +2292,22 @@ def Test_expr7_not()
assert_equal(true, !!'asdf') assert_equal(true, !!'asdf')
assert_equal(true, !![2]) assert_equal(true, !![2])
assert_equal(true, ! false)
assert_equal(true, !! true)
assert_equal(true, ! ! true)
assert_equal(true, !!! false)
assert_equal(true, ! ! ! false)
g:true = true
g:false = false
assert_equal(true, ! g:false)
assert_equal(true, !! g:true)
assert_equal(true, ! ! g:true)
assert_equal(true, !!! g:false)
assert_equal(true, ! ! ! g:false)
unlet g:true
unlet g:false
assert_equal(true, !test_null_partial()) assert_equal(true, !test_null_partial())
assert_equal(false, !{-> 'yes'}) assert_equal(false, !{-> 'yes'})
@ -2314,8 +2330,7 @@ def Test_expr7_not()
assert_equal(false, ![1, 2, 3]->reverse()) assert_equal(false, ![1, 2, 3]->reverse())
assert_equal(true, ![]->reverse()) assert_equal(true, ![]->reverse())
END END
CheckDefSuccess(lines) CheckDefAndScriptSuccess(lines)
CheckScriptSuccess(['vim9script'] + lines)
enddef enddef
func Test_expr7_fails() func Test_expr7_fails()

View File

@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1851,
/**/ /**/
1850, 1850,
/**/ /**/

View File

@ -3041,7 +3041,7 @@ apply_leader(typval_T *rettv, int numeric_only, char_u *start, char_u **end)
++p; ++p;
break; break;
} }
else else if (*p == '!')
{ {
int v = tv2bool(rettv); int v = tv2bool(rettv);
@ -3178,12 +3178,13 @@ compile_leader(cctx_T *cctx, int numeric_only, char_u *start, char_u **end)
} }
else else
{ {
int invert = TRUE; int invert = *p == '!';
while (p > start && p[-1] == '!') while (p > start && (p[-1] == '!' || VIM_ISWHITE(p[-1])))
{ {
if (p[-1] == '!')
invert = !invert;
--p; --p;
invert = !invert;
} }
if (generate_2BOOL(cctx, invert) == FAIL) if (generate_2BOOL(cctx, invert) == FAIL)
return FAIL; return FAIL;