From e15eebd202e739ec7821a0e9c2aa72a445668bb8 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 18 Aug 2020 19:11:38 +0200 Subject: 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 #6729) --- src/eval.c | 2 +- src/proto/typval.pro | 1 + src/testdir/test_vim9_func.vim | 7 +++++++ src/typval.c | 11 +++++++++++ src/version.c | 2 ++ 5 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/eval.c b/src/eval.c index c80013960..585975a80 100644 --- a/src/eval.c +++ b/src/eval.c @@ -326,7 +326,7 @@ eval_expr_to_bool(typval_T *expr, int *error) *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 index 15f934591..25ad3e673 100644 --- 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 index 446ee4d03..79fd80ae1 100644 --- 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 index 053f30077..2203bc6fa 100644 --- 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 index e8eb8521d..fc6884c1e 100644 --- a/src/version.c +++ b/src/version.c @@ -754,6 +754,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1480, /**/ 1479, /**/ -- cgit v1.2.1