]> granicus.if.org Git - vim/commitdiff
patch 8.2.0629: setting a boolean option to v:false does not work v8.2.0629
authorBram Moolenaar <Bram@vim.org>
Fri, 24 Apr 2020 18:57:01 +0000 (20:57 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 24 Apr 2020 18:57:01 +0000 (20:57 +0200)
Problem:    Setting a boolean option to v:false does not work.
Solution:   Do not use the string representation of the value. (Christian
            Brabandt, closes #5974)

src/evalvars.c
src/testdir/test_options.vim
src/version.c

index 1d0599f5ae05db0482ffb1488fa1bc68dd547dca..7c8b9f7accb1cc787059473ae0fffb4b677a1bda 100644 (file)
@@ -1251,13 +1251,15 @@ ex_let_one(
            int         opt_type;
            long        numval;
            char_u      *stringval = NULL;
-           char_u      *s;
+           char_u      *s = NULL;
 
            c1 = *p;
            *p = NUL;
 
            n = (long)tv_get_number(tv);
-           s = tv_get_string_chk(tv);      // != NULL if number or string
+           // avoid setting a string option to the text "v:false" or similar.
+           if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL)
+               s = tv_get_string_chk(tv);      // != NULL if number or string
            if (s != NULL && op != NULL && *op != '=')
            {
                opt_type = get_option_value(arg, &numval,
@@ -1289,7 +1291,8 @@ ex_let_one(
                    }
                }
            }
-           if (s != NULL)
+           if (s != NULL || tv->v_type == VAR_BOOL
+                                                 || tv->v_type == VAR_SPECIAL)
            {
                set_option_value(arg, n, s, opt_flags);
                arg_end = p;
index e03d7e99cc95df67f098b4f63962441ef84c0083..dec82885f6ab79f772fb995183fadb7c33dd62b3 100644 (file)
@@ -899,4 +899,18 @@ func Test_opt_num_op()
   set shiftwidth&
 endfunc
 
+" Test for setting option values using v:false and v:true
+func Test_opt_boolean()
+  set number&
+  set number
+  call assert_equal(1, &nu)
+  set nonu
+  call assert_equal(0, &nu)
+  let &nu = v:true
+  call assert_equal(1, &nu)
+  let &nu = v:false
+  call assert_equal(0, &nu)
+  set number&
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 8782b37a736426ff6b8934cb8c2e0ab130792dad..d22750016fa0a72c78688df9c20352a9bfe1f0c2 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    629,
 /**/
     628,
 /**/