Patch 8.2.1506
Problem: Vim9: no error when using a number other than 0 or 1 as bool.
Solution: Check the number is 0 or 1.
Files: src/errors.h, src/typval.c, src/testdir/test_vim9_func.vim
*** ../vim-8.2.1505/src/errors.h 2020-08-21 22:36:43.662719906 +0200
--- src/errors.h 2020-08-22 14:39:23.354725355 +0200
***************
*** 73,79 ****
INIT(= N_("E1021: const requires a value"));
EXTERN char e_type_or_initialization_required[]
INIT(= N_("E1022: type or initialization required"));
! // E1023 unused
EXTERN char e_using_number_as_string[]
INIT(= N_("E1024: Using a Number as a String"));
EXTERN char e_using_rcurly_outside_if_block_scope[]
--- 73,80 ----
INIT(= N_("E1021: const requires a value"));
EXTERN char e_type_or_initialization_required[]
INIT(= N_("E1022: type or initialization required"));
! EXTERN char e_using_number_as_bool_nr[]
! INIT(= N_("E1023: Using a Number as a Bool: %d"));
EXTERN char e_using_number_as_string[]
INIT(= N_("E1024: Using a Number as a String"));
EXTERN char e_using_rcurly_outside_if_block_scope[]
*** ../vim-8.2.1505/src/typval.c 2020-08-18 19:11:34.486104966 +0200
--- src/typval.c 2020-08-22 14:39:21.902729085 +0200
***************
*** 177,182 ****
--- 177,188 ----
switch (varp->v_type)
{
case VAR_NUMBER:
+ if (want_bool && varp->vval.v_number != 0
+ && varp->vval.v_number != 1)
+ {
+ semsg(_(e_using_number_as_bool_nr), varp->vval.v_number);
+ break;
+ }
return varp->vval.v_number;
case VAR_FLOAT:
#ifdef FEAT_FLOAT
***************
*** 261,273 ****
/*
* 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(typval_T *varp)
{
return tv_get_bool_or_number_chk(varp, NULL, TRUE);
-
}
/*
--- 267,278 ----
/*
* Get the boolean value of "varp". This is like tv_get_number_chk(),
! * but in Vim9 script accepts Number (0 and 1) and Bool/Special.
*/
varnumber_T
tv_get_bool(typval_T *varp)
{
return tv_get_bool_or_number_chk(varp, NULL, TRUE);
}
/*
*** ../vim-8.2.1505/src/testdir/test_vim9_func.vim 2020-08-20
22:29:05.449693697 +0200
--- src/testdir/test_vim9_func.vim 2020-08-22 15:05:34.028731328 +0200
***************
*** 1389,1400 ****
new
setline(1, ['foo', 'bar'])
let val = 0
assert_equal(2, search('bar', 'W', 0, 0, {-> val == 1}))
enddef
def Test_readdir()
! eval expand('.')->readdir({e -> e[0] !=# '.'})
! eval expand('.')->readdirex({e -> e.name[0] !=# '.'})
enddef
def Test_setbufvar()
--- 1389,1410 ----
new
setline(1, ['foo', 'bar'])
let val = 0
+ # skip expr returns boolean
assert_equal(2, search('bar', 'W', 0, 0, {-> val == 1}))
+ :1
+ assert_equal(0, search('bar', 'W', 0, 0, {-> val == 0}))
+ # skip expr returns number, only 0 and 1 are accepted
+ :1
+ assert_equal(2, search('bar', 'W', 0, 0, {-> 0}))
+ :1
+ assert_equal(0, search('bar', 'W', 0, 0, {-> 1}))
+ assert_fails("search('bar', '', 0, 0, {-> -1})", 'E1023:')
+ assert_fails("search('bar', '', 0, 0, {-> -1})", 'E1023:')
enddef
def Test_readdir()
! eval expand('sautest')->readdir({e -> e[0] !=# '.'})
! eval expand('sautest')->readdirex({e -> e.name[0] !=# '.'})
enddef
def Test_setbufvar()
*** ../vim-8.2.1505/src/version.c 2020-08-21 22:46:07.583820586 +0200
--- src/version.c 2020-08-22 14:40:38.118533644 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1506,
/**/
--
hundred-and-one symptoms of being an internet addict:
263. You have more e-mail addresses than shorts.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202008221307.07MD764A710223%40masaka.moolenaar.net.