Skip to content

Commit efc084e

Browse files
committed
patch 8.2.3422: Vim9: no failure if return type differs from returned var
Problem: Vim9: no failure if return type differs from returned variable. Solution: Copy type when copying a list. (closes #8847)
1 parent 6c391a7 commit efc084e

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/list.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ list_copy(list_T *orig, int deep, int copyID)
12171217
copy = list_alloc();
12181218
if (copy != NULL)
12191219
{
1220+
copy->lv_type = orig->lv_type;
12201221
if (copyID != 0)
12211222
{
12221223
// Do this before adding the items, because one of the items may

src/testdir/test_vim9_func.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,29 @@ def Test_return_invalid()
438438
CheckScriptFailure(lines, 'E1010:')
439439
enddef
440440

441+
def Test_return_list_any()
442+
var lines =<< trim END
443+
vim9script
444+
def Func(): list<string>
445+
var l: list<any>
446+
l->add('string')
447+
return l
448+
enddef
449+
echo Func()
450+
END
451+
CheckScriptFailure(lines, 'E1012:')
452+
lines =<< trim END
453+
vim9script
454+
def Func(): list<string>
455+
var l: list<any>
456+
l += ['string']
457+
return l
458+
enddef
459+
echo Func()
460+
END
461+
CheckScriptFailure(lines, 'E1012:')
462+
enddef
463+
441464
func Increment()
442465
let g:counter += 1
443466
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3422,
758760
/**/
759761
3421,
760762
/**/

0 commit comments

Comments
 (0)