changeset 22498:04a9b1399d8e v8.2.1797

patch 8.2.1797: Vim9: some parts of the code not tested Commit: https://github.com/vim/vim/commit/6abd3dc257cf56a8262db38eb15c7cc754e8e002 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Oct 4 14:17:32 2020 +0200 patch 8.2.1797: Vim9: some parts of the code not tested Problem: Vim9: some parts of the code not tested. Solution: Add a few tests.
author Bram Moolenaar <Bram@vim.org>
date Sun, 04 Oct 2020 14:30:05 +0200
parents 6fe73c0d9626
children 8db2a5f8c40a
files src/testdir/test_vim9_func.vim src/version.c
diffstat 2 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -1056,6 +1056,8 @@ def Test_func_type_part()
   CheckDefFailure(['var RefAny: func(): any', 'RefAny = FuncNoArgNoRet'], 'E1012: Type mismatch; expected func(): any but got func()')
   CheckDefFailure(['var RefAny: func(): any', 'RefAny = FuncOneArgNoRet'], 'E1012: Type mismatch; expected func(): any but got func(number)')
 
+  var RefAnyNoArgs: func: any = RefAny
+
   var RefNr: func: number
   RefNr = FuncNoArgRetNumber
   RefNr = FuncOneArgRetNumber
@@ -1100,6 +1102,22 @@ def Test_func_return_type()
   CheckDefFailure(['var str: string', 'str = FuncNoArgRetNumber()'], 'E1012: Type mismatch; expected string but got number')
 enddef
 
+def Test_func_common_type()
+  def FuncOne(n: number): number
+    return n
+  enddef
+  def FuncTwo(s: string): number
+    return len(s)
+  enddef
+  def FuncThree(n: number, s: string): number
+    return n + len(s)
+  enddef
+  var list = [FuncOne, FuncTwo, FuncThree]
+  assert_equal(8, list[0](8))
+  assert_equal(4, list[1]('word'))
+  assert_equal(7, list[2](3, 'word'))
+enddef
+
 def MultiLine(
     arg1: string,
     arg2 = 1234,
@@ -1948,6 +1966,9 @@ def Test_partial_call()
   Xsetlist = function('setqflist', [[], ' '])
   Xsetlist({'title': 'test'})
   getqflist({'title': 1})->assert_equal({'title': 'test'})
+
+  var Len: func: number = function('len', ['word'])
+  assert_equal(4, Len())
 enddef
 
 def Test_cmd_modifier()
--- 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 */
 /**/
+    1797,
+/**/
     1796,
 /**/
     1795,