annotate src/testdir/test_vim9_func.vim @ 20433:5950284a517f v8.2.0771

patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code Commit: https://github.com/vim/vim/commit/6f5b6dfb16228c0ce1e4379b7bafed02eaddbab2 Author: Bram Moolenaar <Bram@vim.org> Date: Sat May 16 21:20:12 2020 +0200 patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code Problem: Vim9: cannot call a compiled closure from not compiled code. Solution: Pass funcexe to call_user_func().
author Bram Moolenaar <Bram@vim.org>
date Sat, 16 May 2020 21:30:10 +0200
parents fc2d76e0994c
children 489cb75c76b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Test various aspects of the Vim9 script language.
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 source check.vim
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 source view_util.vim
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5 source vim9.vim
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 func Test_def_basic()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 def SomeFunc(): string
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 return 'yes'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 call assert_equal('yes', SomeFunc())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 def ReturnString(): string
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 return 'string'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 def ReturnNumber(): number
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 return 123
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 let g:notNumber = 'string'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 def ReturnGlobal(): number
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 return g:notNumber
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 def Test_return_something()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 assert_equal('string', ReturnString())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 assert_equal(123, ReturnNumber())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 assert_fails('call ReturnGlobal()', 'E1029: Expected number but got string')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 let s:nothing = 0
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 def ReturnNothing()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 s:nothing = 1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 if true
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 return
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 endif
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 s:nothing = 2
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 def Test_return_nothing()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 ReturnNothing()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 assert_equal(1, s:nothing)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 func Increment()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 let g:counter += 1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 def Test_call_ufunc_count()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 g:counter = 1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 Increment()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 Increment()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 Increment()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 " works with and without :call
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 assert_equal(4, g:counter)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 call assert_equal(4, g:counter)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 unlet g:counter
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 def MyVarargs(arg: string, ...rest: list<string>): string
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 let res = arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 for s in rest
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 res ..= ',' .. s
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 endfor
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 return res
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 def Test_call_varargs()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 assert_equal('one', MyVarargs('one'))
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 assert_equal('one,two', MyVarargs('one', 'two'))
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 assert_equal('one,two,three', MyVarargs('one', 'two', 'three'))
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 def MyDefaultArgs(name = 'string'): string
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 return name
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 def Test_call_default_args()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 assert_equal('string', MyDefaultArgs())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 assert_equal('one', MyDefaultArgs('one'))
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
86 CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef'], 'E1001:')
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
87 CheckScriptFailure(['def Func(arg: number = "text")', 'enddef'], 'E1013: argument 1: type mismatch, expected number but got string')
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
88 enddef
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
89
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
90 def Test_nested_function()
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
91 def Nested(arg: string): string
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
92 return 'nested ' .. arg
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
93 enddef
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
94 assert_equal('nested function', Nested('function'))
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
95
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
96 CheckDefFailure(['def Nested()', 'enddef', 'Nested(66)'], 'E118:')
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
97 CheckDefFailure(['def Nested(arg: string)', 'enddef', 'Nested()'], 'E119:')
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
98
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
99 CheckDefFailure(['func Nested()', 'endfunc'], 'E1086:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 func Test_call_default_args_from_func()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 call assert_equal('string', MyDefaultArgs())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 call assert_equal('one', MyDefaultArgs('one'))
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 call assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 func TakesOneArg(arg)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 echo a:arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 def Test_call_wrong_args()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 call CheckDefFailure(['TakesOneArg()'], 'E119:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 call CheckDefFailure(['TakesOneArg(11, 22)'], 'E118:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 call CheckDefFailure(['bufnr(xxx)'], 'E1001:')
20253
6f9010b6f7f9 patch 8.2.0682: Vim9: parsing function argument type can get stuck
Bram Moolenaar <Bram@vim.org>
parents: 20247
diff changeset
116 call CheckScriptFailure(['def Func(Ref: func(s: string))'], 'E475:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 " Default arg and varargs
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 def MyDefVarargs(one: string, two = 'foo', ...rest: list<string>): string
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 let res = one .. ',' .. two
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 for s in rest
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 res ..= ',' .. s
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 endfor
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 return res
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 def Test_call_def_varargs()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 call assert_fails('call MyDefVarargs()', 'E119:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 assert_equal('one,foo', MyDefVarargs('one'))
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 assert_equal('one,two', MyDefVarargs('one', 'two'))
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three'))
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
133 call CheckDefFailure(['MyDefVarargs("one", 22)'], 'E1013: argument 2: type mismatch, expected string but got number')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
136 let s:value = ''
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
137
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
138 def FuncOneDefArg(opt = 'text')
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
139 s:value = opt
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
140 enddef
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
141
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
142 def FuncTwoDefArg(nr = 123, opt = 'text'): string
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
143 return nr .. opt
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
144 enddef
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
145
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
146 def FuncVarargs(...arg: list<string>): string
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
147 return join(arg, ',')
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
148 enddef
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
149
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
150 def Test_func_type_varargs()
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
151 let RefDefArg: func(?string)
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
152 RefDefArg = FuncOneDefArg
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
153 RefDefArg()
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
154 assert_equal('text', s:value)
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
155 RefDefArg('some')
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
156 assert_equal('some', s:value)
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
157
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
158 let RefDef2Arg: func(?number, ?string): string
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
159 RefDef2Arg = FuncTwoDefArg
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
160 assert_equal('123text', RefDef2Arg())
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
161 assert_equal('99text', RefDef2Arg(99))
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
162 assert_equal('77some', RefDef2Arg(77, 'some'))
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
163
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
164 call CheckDefFailure(['let RefWrong: func(string?)'], 'E1010:')
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
165 call CheckDefFailure(['let RefWrong: func(?string, string)'], 'E1007:')
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
166
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
167 let RefVarargs: func(...list<string>): string
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
168 RefVarargs = FuncVarargs
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
169 assert_equal('', RefVarargs())
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
170 assert_equal('one', RefVarargs('one'))
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
171 assert_equal('one,two', RefVarargs('one', 'two'))
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
172
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
173 call CheckDefFailure(['let RefWrong: func(...list<string>, string)'], 'E110:')
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
174 call CheckDefFailure(['let RefWrong: func(...list<string>, ?string)'], 'E110:')
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
175 enddef
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
176
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
177 " Only varargs
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
178 def MyVarargsOnly(...args: list<string>): string
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
179 return join(args, ',')
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
180 enddef
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
181
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
182 def Test_call_varargs_only()
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
183 assert_equal('', MyVarargsOnly())
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
184 assert_equal('one', MyVarargsOnly('one'))
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
185 assert_equal('one,two', MyVarargsOnly('one', 'two'))
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
186 call CheckDefFailure(['MyVarargsOnly(1)'], 'E1013: argument 1: type mismatch, expected string but got number')
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
187 call CheckDefFailure(['MyVarargsOnly("one", 2)'], 'E1013: argument 2: type mismatch, expected string but got number')
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
188 enddef
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
189
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 def Test_using_var_as_arg()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 call writefile(['def Func(x: number)', 'let x = 234', 'enddef'], 'Xdef')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 call assert_fails('so Xdef', 'E1006:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 call delete('Xdef')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195
20355
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
196 def DictArg(arg: dict<string>)
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
197 arg['key'] = 'value'
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
198 enddef
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
199
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
200 def ListArg(arg: list<string>)
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
201 arg[0] = 'value'
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
202 enddef
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
203
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
204 def Test_assign_to_argument()
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
205 " works for dict and list
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
206 let d: dict<string> = {}
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
207 DictArg(d)
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
208 assert_equal('value', d['key'])
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
209 let l: list<string> = []
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
210 ListArg(l)
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
211 assert_equal('value', l[0])
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
212
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
213 call CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef'], 'E1090:')
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
214 enddef
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
215
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 def Test_call_func_defined_later()
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
217 call assert_equal('one', g:DefinedLater('one'))
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 call assert_fails('call NotDefined("one")', 'E117:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
221 func DefinedLater(arg)
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
222 return a:arg
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
223 endfunc
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
224
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
225 def Test_call_funcref()
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
226 assert_equal(3, g:SomeFunc('abc'))
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
227 assert_fails('NotAFunc()', 'E117:')
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
228 assert_fails('g:NotAFunc()', 'E117:')
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
229 enddef
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
230
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
231 let SomeFunc = function('len')
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
232 let NotAFunc = 'text'
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
233
19993
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
234 def CombineFuncrefTypes()
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
235 " same arguments, different return type
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
236 let Ref1: func(bool): string
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
237 let Ref2: func(bool): number
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
238 let Ref3: func(bool): any
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
239 Ref3 = g:cond ? Ref1 : Ref2
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
240
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
241 " different number of arguments
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
242 let Refa1: func(bool): number
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
243 let Refa2: func(bool, number): number
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
244 let Refa3: func: number
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
245 Refa3 = g:cond ? Refa1 : Refa2
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
246
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
247 " different argument types
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
248 let Refb1: func(bool, string): number
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
249 let Refb2: func(string, number): number
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
250 let Refb3: func(any, any): number
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
251 Refb3 = g:cond ? Refb1 : Refb2
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
252 enddef
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
253
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 def FuncWithForwardCall()
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
255 return g:DefinedEvenLater("yes")
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 def DefinedEvenLater(arg: string): string
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 return arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 def Test_error_in_nested_function()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 " Error in called function requires unwinding the call stack.
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 assert_fails('call FuncWithForwardCall()', 'E1029')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 def Test_return_type_wrong()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef'], 'expected number but got string')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 CheckScriptFailure(['def Func(): string', 'return 1', 'enddef'], 'expected string but got number')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef'], 'expected void but got string')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 CheckScriptFailure(['def Func()', 'return "a"', 'enddef'], 'expected void but got string')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 CheckScriptFailure(['def Func(): number', 'return', 'enddef'], 'E1003:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
277 CheckScriptFailure(['def Func()', 'return 1'], 'E1057:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 def Test_arg_type_wrong()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 CheckScriptFailure(['def Func3(items: list)', 'echo "a"', 'enddef'], 'E1008: Missing <type>')
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
282 CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: Missing name after ...')
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
283 CheckScriptFailure(['def Func5(items:string)', 'echo "a"'], 'E1069:')
20029
8fb1cf4c44d5 patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents: 20023
diff changeset
284 CheckScriptFailure(['def Func5(items)', 'echo "a"'], 'E1077:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 def Test_vim9script_call()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 let lines =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 vim9script
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 let var = ''
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 def MyFunc(arg: string)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 var = arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 MyFunc('foobar')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 assert_equal('foobar', var)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 let str = 'barfoo'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 str->MyFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 assert_equal('barfoo', var)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 let g:value = 'value'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 g:value->MyFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 assert_equal('value', var)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 let listvar = []
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 def ListFunc(arg: list<number>)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 listvar = arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 [1, 2, 3]->ListFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 assert_equal([1, 2, 3], listvar)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 let dictvar = {}
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 def DictFunc(arg: dict<number>)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 dictvar = arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 {'a': 1, 'b': 2}->DictFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 assert_equal(#{a: 1, b: 2}, dictvar)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 def CompiledDict()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 {'a': 3, 'b': 4}->DictFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 CompiledDict()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 assert_equal(#{a: 3, b: 4}, dictvar)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 #{a: 3, b: 4}->DictFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 assert_equal(#{a: 3, b: 4}, dictvar)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 ('text')->MyFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 assert_equal('text', var)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 ("some")->MyFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 assert_equal('some', var)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 writefile(lines, 'Xcall.vim')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 source Xcall.vim
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 delete('Xcall.vim')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 def Test_vim9script_call_fail_decl()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 let lines =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 vim9script
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 let var = ''
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 def MyFunc(arg: string)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 let var = 123
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 writefile(lines, 'Xcall_decl.vim')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 assert_fails('source Xcall_decl.vim', 'E1054:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 delete('Xcall_decl.vim')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 def Test_vim9script_call_fail_const()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 let lines =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 vim9script
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 const var = ''
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 def MyFunc(arg: string)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 var = 'asdf'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 writefile(lines, 'Xcall_const.vim')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 assert_fails('source Xcall_const.vim', 'E46:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 delete('Xcall_const.vim')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 " Test that inside :function a Python function can be defined, :def is not
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 " recognized.
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 func Test_function_python()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 CheckFeature python3
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 let py = 'python3'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 execute py "<< EOF"
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 def do_something():
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 return 1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 EOF
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 def Test_delfunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 let lines =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 vim9script
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
377 def g:GoneSoon()
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 echo 'hello'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 def CallGoneSoon()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 GoneSoon()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
385 delfunc g:GoneSoon
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 CallGoneSoon()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 writefile(lines, 'XToDelFunc')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 assert_fails('so XToDelFunc', 'E933')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 assert_fails('so XToDelFunc', 'E933')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 delete('XToDelFunc')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 def Test_redef_failure()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 call writefile(['def Func0(): string', 'return "Func0"', 'enddef'], 'Xdef')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 so Xdef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 call writefile(['def Func1(): string', 'return "Func1"', 'enddef'], 'Xdef')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 so Xdef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 call writefile(['def! Func0(): string', 'enddef'], 'Xdef')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 call assert_fails('so Xdef', 'E1027:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 call writefile(['def Func2(): string', 'return "Func2"', 'enddef'], 'Xdef')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 so Xdef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 call delete('Xdef')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
406 call assert_equal(0, g:Func0())
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
407 call assert_equal('Func1', g:Func1())
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
408 call assert_equal('Func2', g:Func2())
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 delfunc! Func0
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 delfunc! Func1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 delfunc! Func2
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
415 def Test_vim9script_func()
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
416 let lines =<< trim END
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
417 vim9script
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
418 func Func(arg)
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
419 echo a:arg
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
420 endfunc
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
421 Func('text')
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
422 END
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
423 writefile(lines, 'XVim9Func')
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
424 so XVim9Func
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
425
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
426 delete('XVim9Func')
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
427 enddef
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
428
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 " Test for internal functions returning different types
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 func Test_InternalFuncRetType()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 let lines =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 def RetFloat(): float
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 return ceil(1.456)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 def RetListAny(): list<any>
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 return items({'k' : 'v'})
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 def RetListString(): list<string>
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 return split('a:b:c', ':')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 def RetListDictAny(): list<dict<any>>
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 return getbufinfo()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 def RetDictNumber(): dict<number>
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 return wordcount()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 def RetDictString(): dict<string>
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 return environ()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 call writefile(lines, 'Xscript')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 source Xscript
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 call assert_equal(2.0, RetFloat())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 call assert_equal([['k', 'v']], RetListAny())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 call assert_equal(['a', 'b', 'c'], RetListString())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 call assert_notequal([], RetListDictAny())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 call assert_notequal({}, RetDictNumber())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 call assert_notequal({}, RetDictString())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 call delete('Xscript')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 " Test for passing too many or too few arguments to internal functions
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 func Test_internalfunc_arg_error()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 let l =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 def! FArgErr(): float
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 return ceil(1.1, 2)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 call writefile(l, 'Xinvalidarg')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 call assert_fails('so Xinvalidarg', 'E118:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 let l =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 def! FArgErr(): float
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 return ceil()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 call writefile(l, 'Xinvalidarg')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 call assert_fails('so Xinvalidarg', 'E119:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 call delete('Xinvalidarg')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 let s:funcResult = 0
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 def FuncNoArgNoRet()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 funcResult = 11
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 def FuncNoArgRetNumber(): number
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 funcResult = 22
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 return 1234
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
498 def FuncNoArgRetString(): string
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
499 funcResult = 45
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
500 return 'text'
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
501 enddef
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
502
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 def FuncOneArgNoRet(arg: number)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 funcResult = arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 def FuncOneArgRetNumber(arg: number): number
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 funcResult = arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 return arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511
19985
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
512 def FuncTwoArgNoRet(one: bool, two: number)
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
513 funcResult = two
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
514 enddef
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
515
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
516 def FuncOneArgRetString(arg: string): string
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
517 return arg
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
518 enddef
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
519
19926
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
520 def FuncOneArgRetAny(arg: any): any
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
521 return arg
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
522 enddef
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
523
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 def Test_func_type()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 let Ref1: func()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 funcResult = 0
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 Ref1 = FuncNoArgNoRet
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 Ref1()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 assert_equal(11, funcResult)
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
530
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
531 let Ref2: func
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
532 funcResult = 0
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
533 Ref2 = FuncNoArgNoRet
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
534 Ref2()
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
535 assert_equal(11, funcResult)
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
536
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
537 funcResult = 0
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
538 Ref2 = FuncOneArgNoRet
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
539 Ref2(12)
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
540 assert_equal(12, funcResult)
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
541
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
542 funcResult = 0
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
543 Ref2 = FuncNoArgRetNumber
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
544 assert_equal(1234, Ref2())
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
545 assert_equal(22, funcResult)
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
546
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
547 funcResult = 0
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
548 Ref2 = FuncOneArgRetNumber
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
549 assert_equal(13, Ref2(13))
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
550 assert_equal(13, funcResult)
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
553 def Test_func_type_part()
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
554 let RefVoid: func: void
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
555 RefVoid = FuncNoArgNoRet
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
556 RefVoid = FuncOneArgNoRet
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
557 CheckDefFailure(['let RefVoid: func: void', 'RefVoid = FuncNoArgRetNumber'], 'E1013: type mismatch, expected func() but got func(): number')
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
558 CheckDefFailure(['let RefVoid: func: void', 'RefVoid = FuncNoArgRetString'], 'E1013: type mismatch, expected func() but got func(): string')
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
559
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
560 let RefAny: func(): any
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
561 RefAny = FuncNoArgRetNumber
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
562 RefAny = FuncNoArgRetString
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
563 CheckDefFailure(['let RefAny: func(): any', 'RefAny = FuncNoArgNoRet'], 'E1013: type mismatch, expected func(): any but got func()')
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
564 CheckDefFailure(['let RefAny: func(): any', 'RefAny = FuncOneArgNoRet'], 'E1013: type mismatch, expected func(): any but got func(number)')
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
565
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
566 let RefNr: func: number
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
567 RefNr = FuncNoArgRetNumber
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
568 RefNr = FuncOneArgRetNumber
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
569 CheckDefFailure(['let RefNr: func: number', 'RefNr = FuncNoArgNoRet'], 'E1013: type mismatch, expected func(): number but got func()')
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
570 CheckDefFailure(['let RefNr: func: number', 'RefNr = FuncNoArgRetString'], 'E1013: type mismatch, expected func(): number but got func(): string')
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
571
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
572 let RefStr: func: string
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
573 RefStr = FuncNoArgRetString
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
574 RefStr = FuncOneArgRetString
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
575 CheckDefFailure(['let RefStr: func: string', 'RefStr = FuncNoArgNoRet'], 'E1013: type mismatch, expected func(): string but got func()')
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
576 CheckDefFailure(['let RefStr: func: string', 'RefStr = FuncNoArgRetNumber'], 'E1013: type mismatch, expected func(): string but got func(): number')
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
577 enddef
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
578
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 def Test_func_type_fails()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 CheckDefFailure(['let ref1: func()'], 'E704:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncNoArgRetNumber'], 'E1013: type mismatch, expected func() but got func(): number')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgNoRet'], 'E1013: type mismatch, expected func() but got func(number)')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgRetNumber'], 'E1013: type mismatch, expected func() but got func(number): number')
19985
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
585 CheckDefFailure(['let Ref1: func(bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: type mismatch, expected func(bool) but got func(bool, number)')
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
586 CheckDefFailure(['let Ref1: func(?bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: type mismatch, expected func(?bool) but got func(bool, number)')
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
587 CheckDefFailure(['let Ref1: func(...bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: type mismatch, expected func(...bool) but got func(bool, number)')
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
588
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
589 call CheckDefFailure(['let RefWrong: func(string ,number)'], 'E1068:')
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
590 call CheckDefFailure(['let RefWrong: func(string,number)'], 'E1069:')
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
591 call CheckDefFailure(['let RefWrong: func(bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool)'], 'E740:')
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
592 call CheckDefFailure(['let RefWrong: func(bool):string'], 'E1069:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594
19926
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
595 def Test_func_return_type()
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
596 let nr: number
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
597 nr = FuncNoArgRetNumber()
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
598 assert_equal(1234, nr)
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
599
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
600 nr = FuncOneArgRetAny(122)
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
601 assert_equal(122, nr)
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
602
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
603 let str: string
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
604 str = FuncOneArgRetAny('yes')
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
605 assert_equal('yes', str)
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
606
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
607 CheckDefFailure(['let str: string', 'str = FuncNoArgRetNumber()'], 'E1013: type mismatch, expected string but got number')
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
608 enddef
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
609
20015
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
610 def MultiLine(
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
611 arg1: string,
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
612 arg2 = 1234,
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
613 ...rest: list<string>
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
614 ): string
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
615 return arg1 .. arg2 .. join(rest, '-')
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
616 enddef
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
617
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
618 def MultiLineComment(
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
619 arg1: string, # comment
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
620 arg2 = 1234, # comment
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
621 ...rest: list<string> # comment
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
622 ): string # comment
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
623 return arg1 .. arg2 .. join(rest, '-')
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
624 enddef
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
625
20015
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
626 def Test_multiline()
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
627 assert_equal('text1234', MultiLine('text'))
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
628 assert_equal('text777', MultiLine('text', 777))
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
629 assert_equal('text777one', MultiLine('text', 777, 'one'))
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
630 assert_equal('text777one-two', MultiLine('text', 777, 'one', 'two'))
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
631 enddef
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
632
20017
ee823254dda5 patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents: 20015
diff changeset
633 func Test_multiline_not_vim9()
ee823254dda5 patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents: 20015
diff changeset
634 call assert_equal('text1234', MultiLine('text'))
ee823254dda5 patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents: 20015
diff changeset
635 call assert_equal('text777', MultiLine('text', 777))
ee823254dda5 patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents: 20015
diff changeset
636 call assert_equal('text777one', MultiLine('text', 777, 'one'))
ee823254dda5 patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents: 20015
diff changeset
637 call assert_equal('text777one-two', MultiLine('text', 777, 'one', 'two'))
ee823254dda5 patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents: 20015
diff changeset
638 endfunc
ee823254dda5 patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents: 20015
diff changeset
639
20015
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
640
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
641 " When using CheckScriptFailure() for the below test, E1010 is generated instead
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
642 " of E1056.
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
643 func Test_E1056_1059()
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
644 let caught_1056 = 0
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
645 try
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
646 def F():
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
647 return 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
648 enddef
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
649 catch /E1056:/
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
650 let caught_1056 = 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
651 endtry
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
652 call assert_equal(1, caught_1056)
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
653
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
654 let caught_1059 = 0
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
655 try
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
656 def F5(items : list)
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
657 echo 'a'
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
658 enddef
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
659 catch /E1059:/
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
660 let caught_1059 = 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
661 endtry
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
662 call assert_equal(1, caught_1059)
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
663 endfunc
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
665 func DelMe()
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
666 echo 'DelMe'
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
667 endfunc
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
668
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
669 def Test_deleted_function()
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
670 CheckDefExecFailure([
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
671 'let RefMe: func = function("g:DelMe")',
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
672 'delfunc g:DelMe',
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
673 'echo RefMe()'], 'E117:')
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
674 enddef
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
675
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
676 def Test_unknown_function()
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
677 CheckDefExecFailure([
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
678 'let Ref: func = function("NotExist")',
20303
98e7b880b7b1 patch 8.2.0707: Vim9 function test fails
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
679 'delfunc g:NotExist'], 'E130:')
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
680 enddef
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
681
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
682 def RefFunc(Ref: func(string): string): string
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
683 return Ref('more')
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
684 enddef
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
685
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
686 def Test_closure_simple()
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
687 let local = 'some '
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
688 assert_equal('some more', RefFunc({s -> local .. s}))
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
689 enddef
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
690
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
691 def MakeRef()
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
692 let local = 'some '
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
693 g:Ref = {s -> local .. s}
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
694 enddef
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
695
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
696 def Test_closure_ref_after_return()
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
697 MakeRef()
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
698 assert_equal('some thing', g:Ref('thing'))
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
699 unlet g:Ref
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
700 enddef
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
701
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
702 def MakeTwoRefs()
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
703 let local = ['some']
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
704 g:Extend = {s -> local->add(s)}
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
705 g:Read = {-> local}
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
706 enddef
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
707
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
708 def Test_closure_two_refs()
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
709 MakeTwoRefs()
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
710 assert_equal('some', join(g:Read(), ' '))
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
711 g:Extend('more')
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
712 assert_equal('some more', join(g:Read(), ' '))
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
713 g:Extend('even')
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
714 assert_equal('some more even', join(g:Read(), ' '))
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
715
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
716 unlet g:Extend
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
717 unlet g:Read
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
718 enddef
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
719
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
720 def ReadRef(Ref: func(): list<string>): string
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
721 return join(Ref(), ' ')
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
722 enddef
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
723
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
724 def ExtendRef(Ref: func(string), add: string)
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
725 Ref(add)
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
726 enddef
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
727
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
728 def Test_closure_two_indirect_refs()
20257
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20255
diff changeset
729 MakeTwoRefs()
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
730 assert_equal('some', ReadRef(g:Read))
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
731 ExtendRef(g:Extend, 'more')
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
732 assert_equal('some more', ReadRef(g:Read))
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
733 ExtendRef(g:Extend, 'even')
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
734 assert_equal('some more even', ReadRef(g:Read))
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
735
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
736 unlet g:Extend
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
737 unlet g:Read
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
738 enddef
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
739
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
740 def MakeArgRefs(theArg: string)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
741 let local = 'loc_val'
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
742 g:UseArg = {s -> theArg .. '/' .. local .. '/' .. s}
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
743 enddef
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
744
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
745 def MakeArgRefsVarargs(theArg: string, ...rest: list<string>)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
746 let local = 'the_loc'
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
747 g:UseVararg = {s -> theArg .. '/' .. local .. '/' .. s .. '/' .. join(rest)}
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
748 enddef
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
749
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
750 def Test_closure_using_argument()
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
751 MakeArgRefs('arg_val')
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
752 assert_equal('arg_val/loc_val/call_val', g:UseArg('call_val'))
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
753
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
754 MakeArgRefsVarargs('arg_val', 'one', 'two')
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
755 assert_equal('arg_val/the_loc/call_val/one two', g:UseVararg('call_val'))
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
756
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
757 unlet g:UseArg
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
758 unlet g:UseVararg
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
759 enddef
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
760
20295
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
761 def MakeGetAndAppendRefs()
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
762 let local = 'a'
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
763
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
764 def Append(arg: string)
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
765 local ..= arg
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
766 enddef
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
767 g:Append = Append
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
768
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
769 def Get(): string
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
770 return local
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
771 enddef
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
772 g:Get = Get
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
773 enddef
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
774
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
775 def Test_closure_append_get()
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
776 MakeGetAndAppendRefs()
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
777 assert_equal('a', g:Get())
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
778 g:Append('-b')
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
779 assert_equal('a-b', g:Get())
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
780 g:Append('-c')
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
781 assert_equal('a-b-c', g:Get())
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
782
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
783 unlet g:Append
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
784 unlet g:Get
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
785 enddef
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
786
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
787 def Test_nested_closure()
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
788 let local = 'text'
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
789 def Closure(arg: string): string
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
790 return local .. arg
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
791 enddef
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
792 assert_equal('text!!!', Closure('!!!'))
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
793 enddef
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
794
20433
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20355
diff changeset
795 func GetResult(Ref)
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20355
diff changeset
796 return a:Ref('some')
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20355
diff changeset
797 endfunc
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20355
diff changeset
798
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20355
diff changeset
799 def Test_call_closure_not_compiled()
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20355
diff changeset
800 let text = 'text'
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20355
diff changeset
801 g:Ref = {s -> s .. text}
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20355
diff changeset
802 assert_equal('sometext', GetResult(g:Ref))
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20355
diff changeset
803 enddef
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20355
diff changeset
804
20257
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20255
diff changeset
805
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker