summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-03-10 12:20:53 +0000
committerBram Moolenaar <Bram@vim.org>2022-03-10 12:20:53 +0000
commitf8691004b069f67becd657a02100d7521d1255a9 (patch)
tree4103e48dced85681f6c85ae4023b74a9becdb111
parent56b84b1728e68f984446ec2698716cb8a1f6871d (diff)
downloadvim-git-f8691004b069f67becd657a02100d7521d1255a9.tar.gz
patch 8.2.4534: Vim9: "is" operator with empty string and null returns truev8.2.4534
Problem: Vim9: "is" operator with empty string and null returns true. Solution: Consider empty string and null to be different for "is".
-rw-r--r--src/testdir/test_vim9_expr.vim7
-rw-r--r--src/typval.c18
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c5
4 files changed, 27 insertions, 5 deletions
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 4a3803a8f..72e85de3f 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -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
diff --git a/src/typval.c b/src/typval.c
index 53512c649..e0511be85 100644
--- a/src/typval.c
+++ b/src/typval.c
@@ -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;
diff --git a/src/version.c b/src/version.c
index 9b72517a5..5e5a2a8aa 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4534,
+/**/
4533,
/**/
4532,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 9f6cc5d91..d908e6431 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -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;