diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-08-17 21:41:02 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-08-17 21:41:02 +0200 |
commit | 36967b32fd02eaab4273c1a1e7a1210a5fe45d09 (patch) | |
tree | 34de67c1d4d14063179da865bd40c6982fc29904 | |
parent | 624b6eaf20f3e8c669425b6a32f17fb9ec2ebbd2 (diff) |
patch 8.2.1475: Vim9: can't use v:true for option flagsv8.2.1475
Problem: Vim9: can't use v:true for option flags.
Solution: Add tv_get_bool_chk(). (closes #6725)
-rw-r--r-- | src/channel.c | 14 | ||||
-rw-r--r-- | src/proto/typval.pro | 1 | ||||
-rw-r--r-- | src/typval.c | 55 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 46 insertions, 26 deletions
diff --git a/src/channel.c b/src/channel.c index f20a4d851d..3e7ec96598 100644 --- a/src/channel.c +++ b/src/channel.c @@ -4922,7 +4922,7 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2) { if (!(supported & JO_MODE)) break; - opt->jo_noblock = tv_get_number(item); + opt->jo_noblock = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "in_io") == 0 || STRCMP(hi->hi_key, "out_io") == 0 @@ -4949,7 +4949,7 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2) { if (!(supported & JO_MODE)) break; - opt->jo_pty = tv_get_number(item); + opt->jo_pty = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "in_buf") == 0 || STRCMP(hi->hi_key, "out_buf") == 0 @@ -4980,7 +4980,7 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2) if (!(supported & JO_OUT_IO)) break; opt->jo_set |= JO_OUT_MODIFIABLE << (part - PART_OUT); - opt->jo_modifiable[part] = tv_get_number(item); + opt->jo_modifiable[part] = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "out_msg") == 0 || STRCMP(hi->hi_key, "err_msg") == 0) @@ -4990,7 +4990,7 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2) if (!(supported & JO_OUT_IO)) break; opt->jo_set2 |= JO2_OUT_MSG << (part - PART_OUT); - opt->jo_message[part] = tv_get_number(item); + opt->jo_message[part] = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "in_top") == 0 || STRCMP(hi->hi_key, "in_bot") == 0) @@ -5184,7 +5184,7 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2) if (!(supported2 & JO2_VERTICAL)) break; opt->jo_set2 |= JO2_VERTICAL; - opt->jo_vertical = tv_get_number(item); + opt->jo_vertical = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "curwin") == 0) { @@ -5224,14 +5224,14 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2) if (!(supported2 & JO2_HIDDEN)) break; opt->jo_set2 |= JO2_HIDDEN; - opt->jo_hidden = tv_get_number(item); + opt->jo_hidden = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "norestore") == 0) { if (!(supported2 & JO2_NORESTORE)) break; opt->jo_set2 |= JO2_NORESTORE; - opt->jo_term_norestore = tv_get_number(item); + opt->jo_term_norestore = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "term_kill") == 0) { diff --git a/src/proto/typval.pro b/src/proto/typval.pro index 3bc2f2c5e5..15f9345912 100644 --- a/src/proto/typval.pro +++ b/src/proto/typval.pro @@ -6,6 +6,7 @@ void clear_tv(typval_T *varp); 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); 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/typval.c b/src/typval.c index 406a193be3..053f30077e 100644 --- a/src/typval.c +++ b/src/typval.c @@ -169,24 +169,8 @@ init_tv(typval_T *varp) CLEAR_POINTER(varp); } -/* - * Get the number value of a variable. - * If it is a String variable, uses vim_str2nr(). - * For incompatible types, return 0. - * tv_get_number_chk() is similar to tv_get_number(), but informs the - * caller of incompatible types: it sets *denote to TRUE if "denote" - * is not NULL or returns -1 otherwise. - */ - varnumber_T -tv_get_number(typval_T *varp) -{ - int error = FALSE; - - return tv_get_number_chk(varp, &error); // return 0L on error -} - - varnumber_T -tv_get_number_chk(typval_T *varp, int *denote) + static varnumber_T +tv_get_bool_or_number_chk(typval_T *varp, int *denote, int want_bool) { varnumber_T n = 0L; @@ -221,7 +205,7 @@ tv_get_number_chk(typval_T *varp, int *denote) break; case VAR_BOOL: case VAR_SPECIAL: - if (in_vim9script()) + if (!want_bool && in_vim9script()) { emsg(_("E611: Using a Special as a Number")); break; @@ -253,6 +237,39 @@ tv_get_number_chk(typval_T *varp, int *denote) return n; } +/* + * Get the number value of a variable. + * If it is a String variable, uses vim_str2nr(). + * For incompatible types, return 0. + * tv_get_number_chk() is similar to tv_get_number(), but informs the + * caller of incompatible types: it sets *denote to TRUE if "denote" + * is not NULL or returns -1 otherwise. + */ + varnumber_T +tv_get_number(typval_T *varp) +{ + int error = FALSE; + + return tv_get_number_chk(varp, &error); // return 0L on error +} + + varnumber_T +tv_get_number_chk(typval_T *varp, int *denote) +{ + return tv_get_bool_or_number_chk(varp, denote, FALSE); +} + +/* + * 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); + +} + #ifdef FEAT_FLOAT float_T tv_get_float(typval_T *varp) diff --git a/src/version.c b/src/version.c index afd3aaa11a..83af396021 100644 --- 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 */ /**/ + 1475, +/**/ 1474, /**/ 1473, |