summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-09-09 22:30:52 +0200
committerBram Moolenaar <Bram@vim.org>2021-09-09 22:30:52 +0200
commitefc084e3353d6854b6dac8b240f70cb0abb838ad (patch)
tree3abfd67a91c755bd3e63b041702d8f7f96112c76
parent6c391a74fe90190796ca0b0c010112948a6e75d7 (diff)
downloadvim-git-efc084e3353d6854b6dac8b240f70cb0abb838ad.tar.gz
patch 8.2.3422: Vim9: no failure if return type differs from returned varv8.2.3422
Problem: Vim9: no failure if return type differs from returned variable. Solution: Copy type when copying a list. (closes #8847)
-rw-r--r--src/list.c1
-rw-r--r--src/testdir/test_vim9_func.vim23
-rw-r--r--src/version.c2
3 files changed, 26 insertions, 0 deletions
diff --git a/src/list.c b/src/list.c
index 76101bac5..336bf3ba7 100644
--- a/src/list.c
+++ b/src/list.c
@@ -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
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 09f80e9d1..4e2f70e05 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index d1767f349..8cd295c1b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3422,
+/**/
3421,
/**/
3420,