]> granicus.if.org Git - vim/commitdiff
patch 8.2.4534: Vim9: "is" operator with empty string and null returns true v8.2.4534
authorBram Moolenaar <Bram@vim.org>
Thu, 10 Mar 2022 12:20:53 +0000 (12:20 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 10 Mar 2022 12:20:53 +0000 (12:20 +0000)
Problem:    Vim9: "is" operator with empty string and null returns true.
Solution:   Consider empty string and null to be different for "is".

src/testdir/test_vim9_expr.vim
src/typval.c
src/version.c
src/vim9execute.c

index 4a3803a8f1178fc6999f555eed72cc95eed02593..72e85de3fdab72e968b5abd1f93db32612351171 100644 (file)
@@ -801,6 +801,13 @@ def Test_expr4_compare_null()
       assert_false(null_string != null)
       assert_false(v:null != test_null_string())
       assert_false(null != null_string)
+
+      assert_true(null_string is test_null_string())
+      assert_false(null_string is '')
+      assert_false('' is null_string)
+      assert_false(null_string isnot test_null_string())
+      assert_true(null_string isnot '')
+      assert_true('' isnot null_string)
   END
   v9.CheckDefAndScriptSuccess(lines)
   unlet g:null_dict
index 53512c64985839c33197bfe8b8c8857c46e0eaba..e0511be8501894058e07646550f64fc1a026f045 100644 (file)
@@ -1583,9 +1583,23 @@ typval_compare_string(
        i = ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2);
     switch (type)
     {
-       case EXPR_IS:
+       case EXPR_IS:       if (in_vim9script())
+                           {
+                               // Really check it is the same string, not just
+                               // the same value.
+                               val = tv1->vval.v_string == tv2->vval.v_string;
+                               break;
+                           }
+                           // FALLTHROUGH
        case EXPR_EQUAL:    val = (i == 0); break;
-       case EXPR_ISNOT:
+       case EXPR_ISNOT:    if (in_vim9script())
+                           {
+                               // Really check it is not the same string, not
+                               // just a different value.
+                               val = tv1->vval.v_string != tv2->vval.v_string;
+                               break;
+                           }
+                           // FALLTHROUGH
        case EXPR_NEQUAL:   val = (i != 0); break;
        case EXPR_GREATER:  val = (i > 0); break;
        case EXPR_GEQUAL:   val = (i >= 0); break;
index 9b72517a5d51e9cbd61c3b4b4323b3f9f9bd2146..5e5a2a8aa23bb13d685c07872550a27a09656d33 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4534,
 /**/
     4533,
 /**/
index 9f6cc5d91c496ac45f571d8760c723737ee4c8c2..d908e64314ca5ed82518f3882ec2ba7f466fdef5 100644 (file)
@@ -3313,9 +3313,8 @@ exec_instructions(ectx_T *ectx)
                        break;
                    default:
                        tv->v_type = VAR_STRING;
-                       tv->vval.v_string = vim_strsave(
-                               iptr->isn_arg.string == NULL
-                                       ? (char_u *)"" : iptr->isn_arg.string);
+                       tv->vval.v_string = iptr->isn_arg.string == NULL
+                                   ? NULL : vim_strsave(iptr->isn_arg.string);
                }
                break;