1
0
forked from aniani/vim

patch 8.2.0695: Vim9: cannot define a function inside a function

Problem:    Vim9: cannot define a function inside a function.
Solution:   Initial support for :def inside :def.
This commit is contained in:
Bram Moolenaar
2020-05-04 23:24:44 +02:00
parent 80a8d3889b
commit 04b1269783
6 changed files with 167 additions and 72 deletions

View File

@@ -2,19 +2,7 @@
source check.vim
source view_util.vim
" Check that "lines" inside ":def" results in an "error" message.
func CheckDefFailure(lines, error)
call writefile(['def Func()'] + a:lines + ['enddef'], 'Xdef')
call assert_fails('so Xdef', a:error, a:lines)
call delete('Xdef')
endfunc
func CheckScriptFailure(lines, error)
call writefile(a:lines, 'Xdef')
call assert_fails('so Xdef', a:error, a:lines)
call delete('Xdef')
endfunc
source vim9.vim
func Test_def_basic()
def SomeFunc(): string
@@ -95,8 +83,17 @@ def Test_call_default_args()
assert_equal('one', MyDefaultArgs('one'))
assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
call CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef'], 'E1001:')
call CheckScriptFailure(['def Func(arg: number = "text")', 'enddef'], 'E1013: argument 1: type mismatch, expected number but got string')
CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef'], 'E1001:')
CheckScriptFailure(['def Func(arg: number = "text")', 'enddef'], 'E1013: argument 1: type mismatch, expected number but got string')
enddef
def Test_nested_function()
def Nested(arg: string): string
return 'nested ' .. arg
enddef
assert_equal('nested function', Nested('function'))
CheckDefFailure(['func Nested()', 'endfunc'], 'E1086:')
enddef
func Test_call_default_args_from_func()
@@ -721,5 +718,13 @@ def Test_closure_using_argument()
unlet g:UseVararg
enddef
def Test_nested_closure()
let local = 'text'
def Closure(arg: string): string
return local .. arg
enddef
assert_equal('text!!!', Closure('!!!'))
enddef
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker