]> granicus.if.org Git - vim/commitdiff
patch 8.2.3422: Vim9: no failure if return type differs from returned var v8.2.3422
authorBram Moolenaar <Bram@vim.org>
Thu, 9 Sep 2021 20:30:52 +0000 (22:30 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 9 Sep 2021 20:30:52 +0000 (22:30 +0200)
Problem:    Vim9: no failure if return type differs from returned variable.
Solution:   Copy type when copying a list. (closes #8847)

src/list.c
src/testdir/test_vim9_func.vim
src/version.c

index 76101bac5e503c80e23ca927b3778c67e68fefb0..336bf3ba76d5416b11f115619f71503cd3b382bd 100644 (file)
@@ -1217,6 +1217,7 @@ list_copy(list_T *orig, int deep, int copyID)
     copy = list_alloc();
     if (copy != NULL)
     {
+       copy->lv_type = orig->lv_type;
        if (copyID != 0)
        {
            // Do this before adding the items, because one of the items may
index 09f80e9d19b808629b89d6302a2f8327e7d13d6a..4e2f70e05dfc17ff4c8743521fbb15bf39cce352 100644 (file)
@@ -438,6 +438,29 @@ def Test_return_invalid()
   CheckScriptFailure(lines, 'E1010:')
 enddef
 
+def Test_return_list_any()
+  var lines =<< trim END
+      vim9script
+      def Func(): list<string>
+        var l: list<any>
+        l->add('string')
+        return l
+      enddef
+      echo Func()
+  END
+  CheckScriptFailure(lines, 'E1012:')
+  lines =<< trim END
+      vim9script
+      def Func(): list<string>
+        var l: list<any>
+        l += ['string']
+        return l
+      enddef
+      echo Func()
+  END
+  CheckScriptFailure(lines, 'E1012:')
+enddef
+
 func Increment()
   let g:counter += 1
 endfunc
index d1767f3497e075c81f0904059cd63774cbb5d77a..8cd295c1bbbf986040071ee47155b4b8ca41ac1e 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3422,
 /**/
     3421,
 /**/