# HG changeset patch # User Bram Moolenaar # Date 1597770904 -7200 # Node ID cd8dafe937ba398ba47c172e846c8a4e52864f4a # Parent 2b26ea27117dc7b2b86158f1c72144e99e4ef3b2 patch 8.2.1480: Vim9: skip expression in search() gives error Commit: https://github.com/vim/vim/commit/e15eebd202e739ec7821a0e9c2aa72a445668bb8 Author: Bram Moolenaar Date: Tue Aug 18 19:11:38 2020 +0200 patch 8.2.1480: Vim9: skip expression in search() gives error Problem: Vim9: skip expression in search() gives error. Solution: use tv_get_bool() eval_expr_to_bool(). (closes https://github.com/vim/vim/issues/6729) diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -326,7 +326,7 @@ eval_expr_to_bool(typval_T *expr, int *e *error = TRUE; return FALSE; } - res = (tv_get_number_chk(&rettv, error) != 0); + res = (tv_get_bool_chk(&rettv, error) != 0); clear_tv(&rettv); return res; } diff --git a/src/proto/typval.pro b/src/proto/typval.pro --- a/src/proto/typval.pro +++ b/src/proto/typval.pro @@ -7,6 +7,7 @@ void init_tv(typval_T *varp); varnumber_T tv_get_number(typval_T *varp); varnumber_T tv_get_number_chk(typval_T *varp, int *denote); varnumber_T tv_get_bool(typval_T *varp); +varnumber_T tv_get_bool_chk(typval_T *varp, int *denote); float_T tv_get_float(typval_T *varp); char_u *tv_get_string(typval_T *varp); char_u *tv_get_string_buf(typval_T *varp, char_u *buf); diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -1379,6 +1379,13 @@ func Test_silent_echo() call delete('XTest_silent_echo') endfunc +def Test_search() + new + setline(1, ['foo', 'bar']) + let val = 0 + assert_equal(2, search('bar', 'W', 0, 0, {-> val == 1})) +enddef + def Fibonacci(n: number): number if n < 2 return n diff --git a/src/typval.c b/src/typval.c --- a/src/typval.c +++ b/src/typval.c @@ -270,6 +270,17 @@ tv_get_bool(typval_T *varp) } +/* + * Get the boolean value of "varp". This is like tv_get_number_chk(), + * but in Vim9 script accepts Number and Bool. + */ + varnumber_T +tv_get_bool_chk(typval_T *varp, int *denote) +{ + return tv_get_bool_or_number_chk(varp, denote, TRUE); + +} + #ifdef FEAT_FLOAT float_T tv_get_float(typval_T *varp) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1480, +/**/ 1479, /**/ 1478,