patch 9.1.0299: Vim9: return type not set for a lambda assigned to script var

Problem:  Vim9: return type not set for a lambda assigned to script var
          (Ernie Rael)
Solution: Correctly determine the return type (Yegappan Lakshmanan)

fixes: #14445
closes: #14473

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim
index 82dc3e5..0d6d783 100644
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -1104,6 +1104,27 @@
       Ref(0)
   END
   v9.CheckScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected string but got number')
+
+  lines =<< trim END
+    var Fn1 = () => {
+        return 10
+      }
+    assert_equal('func(): number', typename(Fn1))
+    var Fn2 = () => {
+        return "a"
+      }
+    assert_equal('func(): string', typename(Fn2))
+    var Fn3 = () => {
+        return {a: [1]}
+      }
+    assert_equal('func(): dict<list<number>>', typename(Fn3))
+    var Fn4 = (...l: list<string>) => {
+        return []
+      }
+    assert_equal('func(...list<string>): list<any>', typename(Fn4))
+  END
+  v9.CheckSourceSuccess(['vim9script'] + lines)
+  v9.CheckSourceSuccess(['def Xfunc()'] + lines + ['enddef', 'defcompile'])
 enddef
 
 def Test_assignment_list_any_index()
diff --git a/src/testdir/vim9.vim b/src/testdir/vim9.vim
index 782809b..764b611 100644
--- a/src/testdir/vim9.vim
+++ b/src/testdir/vim9.vim
@@ -112,11 +112,13 @@
 
 # :source a list of "lines" and check whether it fails with "error"
 export def CheckSourceFailure(lines: list<string>, error: string, lnum = -3)
+  var cwd = getcwd()
   new
   setline(1, lines)
   try
     assert_fails('source', error, lines, lnum)
   finally
+    chdir(cwd)
     bw!
   endtry
 enddef
@@ -124,22 +126,26 @@
 # :source a list of "lines" and check whether it fails with the list of
 # "errors"
 export def CheckSourceFailureList(lines: list<string>, errors: list<string>, lnum = -3)
+  var cwd = getcwd()
   new
   setline(1, lines)
   try
     assert_fails('source', errors, lines, lnum)
   finally
+    chdir(cwd)
     bw!
   endtry
 enddef
 
 # :source a list of "lines" and check whether it succeeds
 export def CheckSourceSuccess(lines: list<string>)
+  var cwd = getcwd()
   new
   setline(1, lines)
   try
     :source
   finally
+    chdir(cwd)
     bw!
   endtry
 enddef