]> granicus.if.org Git - vim/commitdiff
patch 8.2.1852: map() returing zero for NULL list is unexpected v8.2.1852
authorBram Moolenaar <Bram@vim.org>
Thu, 15 Oct 2020 20:29:17 +0000 (22:29 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 15 Oct 2020 20:29:17 +0000 (22:29 +0200)
Problem:    map() returing zero for NULL list is unexpected.
Solution:   Return the empty list. (closes #7133)

src/list.c
src/testdir/test_blob.vim
src/testdir/test_filter_map.vim
src/version.c

index 59c614ffbc083447576f89b36c74df1aade40040..62c571c71413e120e8b7cb24273d9b6e1e385888 100644 (file)
@@ -1961,6 +1961,9 @@ filter_map(typval_T *argvars, typval_T *rettv, int map)
     int                save_did_emsg;
     int                idx = 0;
 
+    // Always return the first argument, also on failure.
+    copy_tv(&argvars[0], rettv);
+
     if (argvars[0].v_type == VAR_BLOB)
     {
        if ((b = argvars[0].vval.v_blob) == NULL)
@@ -2110,8 +2113,6 @@ filter_map(typval_T *argvars, typval_T *rettv, int map)
 
        did_emsg |= save_did_emsg;
     }
-
-    copy_tv(&argvars[0], rettv);
 }
 
 /*
index 69b3504799925ceed7b2fb4832012b4f0bd2a34e..3eff715d05e3ba70e96a8aaf9b63f2a564b56a5d 100644 (file)
@@ -271,6 +271,7 @@ endfunc
 
 " filter() item in blob
 func Test_blob_filter()
+  call assert_equal(test_null_blob(), filter(test_null_blob(), '0'))
   call assert_equal(0z, filter(0zDEADBEEF, '0'))
   call assert_equal(0zADBEEF, filter(0zDEADBEEF, 'v:val != 0xDE'))
   call assert_equal(0zDEADEF, filter(0zDEADBEEF, 'v:val != 0xBE'))
index 249c32f126f579cd9366a64c19431a80d10c3f15..e6587c23bdc4b22aa56d218b8a158eef99288465 100644 (file)
@@ -98,10 +98,10 @@ func Test_map_filter_fails()
   call assert_fails("let l = filter([1, 2, 3], '{}')", 'E728:')
   call assert_fails("let l = filter({'k' : 10}, '{}')", 'E728:')
   call assert_fails("let l = filter([1, 2], {})", 'E731:')
-  call assert_equal(0, filter(test_null_list(), 0))
-  call assert_equal(0, filter(test_null_dict(), 0))
-  call assert_equal(0, map(test_null_list(), '"> " .. v:val'))
-  call assert_equal(0, map(test_null_dict(), '"> " .. v:val'))
+  call assert_equal(test_null_list(), filter(test_null_list(), 0))
+  call assert_equal(test_null_dict(), filter(test_null_dict(), 0))
+  call assert_equal(test_null_list(), map(test_null_list(), '"> " .. v:val'))
+  call assert_equal(test_null_dict(), map(test_null_dict(), '"> " .. v:val'))
   call assert_equal([1, 2, 3], filter([1, 2, 3], test_null_function()))
   call assert_fails("let l = filter([1, 2], function('min'))", 'E118:')
   call assert_equal([1, 2, 3], filter([1, 2, 3], test_null_partial()))
index 934b82215c55b268ab27faa4acb8763de879ed03..266c7c135b39e099f6369d3b4069d2a3f2418960 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1852,
 /**/
     1851,
 /**/