annotate src/testdir/test_vim9_func.vim @ 21969:ba2415df82d7 v8.2.1534

patch 8.2.1534: Vim9: type error for argument type is not at call position Commit: https://github.com/vim/vim/commit/ee8580e52e767916e2a95e8ac0732fd8a5ae0651 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 28 17:19:07 2020 +0200 patch 8.2.1534: Vim9: type error for argument type is not at call position Problem: Vim9: type error for argument type is not at call position. Solution: Set the context and stack after checking the arguments. (issue #6785)
author Bram Moolenaar <Bram@vim.org>
date Fri, 28 Aug 2020 17:30:04 +0200
parents bf68435a695a
children c9517003821d
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
21172
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
6 source screendump.vim
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 func Test_def_basic()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 def SomeFunc(): string
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 return 'yes'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 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
13 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 def ReturnString(): string
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 return 'string'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 def ReturnNumber(): number
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 return 123
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 let g:notNumber = 'string'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 def ReturnGlobal(): number
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 return g:notNumber
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 def Test_return_something()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 assert_equal('string', ReturnString())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 assert_equal(123, ReturnNumber())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 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
33 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
35 def Test_missing_return()
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
36 CheckDefFailure(['def Missing(): number',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
37 ' if g:cond',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
38 ' echo "no return"',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
39 ' else',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
40 ' return 0',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
41 ' endif'
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
42 'enddef'], 'E1027:')
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
43 CheckDefFailure(['def Missing(): number',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
44 ' if g:cond',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
45 ' return 1',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
46 ' else',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
47 ' echo "no return"',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
48 ' endif'
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
49 'enddef'], 'E1027:')
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
50 CheckDefFailure(['def Missing(): number',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
51 ' if g:cond',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
52 ' return 1',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
53 ' else',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
54 ' return 2',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
55 ' endif'
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
56 ' return 3'
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
57 'enddef'], 'E1095:')
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
58 enddef
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
59
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 let s:nothing = 0
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 def ReturnNothing()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 s:nothing = 1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 if true
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 return
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 endif
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 s:nothing = 2
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 def Test_return_nothing()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 ReturnNothing()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 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
72 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 func Increment()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 let g:counter += 1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 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
79 g:counter = 1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 Increment()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 Increment()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 Increment()
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21347
diff changeset
83 # works with and without :call
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 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
85 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
86 unlet g:counter
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 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
90 let res = arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 for s in rest
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 res ..= ',' .. s
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 endfor
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 return res
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 def Test_call_varargs()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 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
99 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
100 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
101 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 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
104 return name
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106
21345
5dd4cbc1e9e6 patch 8.2.1223: Vim9: invalid type error for function default value
Bram Moolenaar <Bram@vim.org>
parents: 21335
diff changeset
107 def MyDefaultSecond(name: string, second: bool = true): string
5dd4cbc1e9e6 patch 8.2.1223: Vim9: invalid type error for function default value
Bram Moolenaar <Bram@vim.org>
parents: 21335
diff changeset
108 return second ? name : 'none'
5dd4cbc1e9e6 patch 8.2.1223: Vim9: invalid type error for function default value
Bram Moolenaar <Bram@vim.org>
parents: 21335
diff changeset
109 enddef
5dd4cbc1e9e6 patch 8.2.1223: Vim9: invalid type error for function default value
Bram Moolenaar <Bram@vim.org>
parents: 21335
diff changeset
110
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 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
112 assert_equal('string', MyDefaultArgs())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 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
114 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
115
21345
5dd4cbc1e9e6 patch 8.2.1223: Vim9: invalid type error for function default value
Bram Moolenaar <Bram@vim.org>
parents: 21335
diff changeset
116 assert_equal('test', MyDefaultSecond('test'))
5dd4cbc1e9e6 patch 8.2.1223: Vim9: invalid type error for function default value
Bram Moolenaar <Bram@vim.org>
parents: 21335
diff changeset
117 assert_equal('test', MyDefaultSecond('test', true))
5dd4cbc1e9e6 patch 8.2.1223: Vim9: invalid type error for function default value
Bram Moolenaar <Bram@vim.org>
parents: 21335
diff changeset
118 assert_equal('none', MyDefaultSecond('test', false))
5dd4cbc1e9e6 patch 8.2.1223: Vim9: invalid type error for function default value
Bram Moolenaar <Bram@vim.org>
parents: 21335
diff changeset
119
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
120 CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:')
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
121 CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: argument 1: type mismatch, expected number but got string')
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
122 enddef
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
123
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
124 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
125 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
126 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
127 enddef
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
128 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
129
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
130 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
131 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
132
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
133 CheckDefFailure(['func Nested()', 'endfunc'], 'E1086:')
21602
7028f45bf0ea patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents: 21588
diff changeset
134 CheckDefFailure(['def s:Nested()', 'enddef'], 'E1075:')
7028f45bf0ea patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents: 21588
diff changeset
135 CheckDefFailure(['def b:Nested()', 'enddef'], 'E1075:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137
21566
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
138 func Test_call_default_args_from_func()
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
139 call assert_equal('string', MyDefaultArgs())
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
140 call assert_equal('one', MyDefaultArgs('one'))
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
141 call assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
142 endfunc
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
143
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
144 def Test_nested_global_function()
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
145 let lines =<< trim END
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
146 vim9script
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
147 def Outer()
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
148 def g:Inner(): string
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
149 return 'inner'
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
150 enddef
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
151 enddef
21566
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
152 defcompile
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
153 Outer()
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
154 assert_equal('inner', g:Inner())
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
155 delfunc g:Inner
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
156 Outer()
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
157 assert_equal('inner', g:Inner())
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
158 delfunc g:Inner
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
159 Outer()
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
160 assert_equal('inner', g:Inner())
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
161 delfunc g:Inner
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
162 END
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
163 CheckScriptSuccess(lines)
21588
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
164
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
165 lines =<< trim END
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
166 vim9script
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
167 def Outer()
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
168 def g:Inner(): string
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
169 return 'inner'
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
170 enddef
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
171 enddef
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
172 defcompile
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
173 Outer()
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
174 Outer()
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
175 END
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
176 CheckScriptFailure(lines, "E122:")
21604
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
177
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
178 lines =<< trim END
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
179 vim9script
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
180 def Func()
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
181 echo 'script'
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
182 enddef
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
183 def Outer()
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
184 def Func()
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
185 echo 'inner'
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
186 enddef
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
187 enddef
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
188 defcompile
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
189 END
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
190 CheckScriptFailure(lines, "E1073:")
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
191 enddef
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
192
21586
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
193 def Test_global_local_function()
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
194 let lines =<< trim END
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
195 vim9script
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
196 def g:Func(): string
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
197 return 'global'
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
198 enddef
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
199 def Func(): string
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
200 return 'local'
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
201 enddef
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
202 assert_equal('global', g:Func())
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
203 assert_equal('local', Func())
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
204 END
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
205 CheckScriptSuccess(lines)
21747
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
206
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
207 lines =<< trim END
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
208 vim9script
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
209 def g:Funcy()
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
210 echo 'funcy'
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
211 enddef
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
212 s:Funcy()
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
213 END
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
214 CheckScriptFailure(lines, 'E117:')
21586
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
215 enddef
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
216
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 func TakesOneArg(arg)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 echo a:arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 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
222 call CheckDefFailure(['TakesOneArg()'], 'E119:')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 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
224 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
225 call CheckScriptFailure(['def Func(Ref: func(s: string))'], 'E475:')
21969
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21967
diff changeset
226
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21967
diff changeset
227 let lines =<< trim END
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21967
diff changeset
228 vim9script
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21967
diff changeset
229 def Func(s: string)
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21967
diff changeset
230 echo s
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21967
diff changeset
231 enddef
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21967
diff changeset
232 Func([])
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21967
diff changeset
233 END
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21967
diff changeset
234 call CheckScriptFailure(lines, 'E1012: type mismatch, expected string but got list<unknown>', 5)
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 " Default arg and varargs
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 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
239 let res = one .. ',' .. two
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 for s in rest
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 res ..= ',' .. s
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 endfor
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 return res
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 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
247 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
248 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
249 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
250 assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three'))
21481
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
251 CheckDefFailure(['MyDefVarargs("one", 22)'],
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
252 'E1013: argument 2: type mismatch, expected string but got number')
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
253 CheckDefFailure(['MyDefVarargs("one", "two", 123)'],
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
254 'E1013: argument 3: type mismatch, expected string but got number')
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
255
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
256 let lines =<< trim END
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
257 vim9script
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
258 def Func(...l: list<string>)
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
259 echo l
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
260 enddef
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
261 Func('a', 'b', 'c')
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
262 END
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
263 CheckScriptSuccess(lines)
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
264
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
265 lines =<< trim END
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
266 vim9script
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
267 def Func(...l: list<string>)
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
268 echo l
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
269 enddef
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
270 Func()
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
271 END
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
272 CheckScriptSuccess(lines)
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
273
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
274 lines =<< trim END
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
275 vim9script
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
276 def Func(...l: list<string>)
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
277 echo l
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
278 enddef
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
279 Func(1, 2, 3)
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
280 END
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
281 CheckScriptFailure(lines, 'E1012:')
21481
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
282
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
283 lines =<< trim END
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
284 vim9script
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
285 def Func(...l: list<string>)
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
286 echo l
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
287 enddef
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
288 Func('a', 9)
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
289 END
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
290 CheckScriptFailure(lines, 'E1012:')
21481
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
291
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
292 lines =<< trim END
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
293 vim9script
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
294 def Func(...l: list<string>)
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
295 echo l
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
296 enddef
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
297 Func(1, 'a')
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
298 END
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
299 CheckScriptFailure(lines, 'E1012:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301
21751
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21747
diff changeset
302 def Test_call_call()
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21747
diff changeset
303 let l = [3, 2, 1]
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21747
diff changeset
304 call('reverse', [l])
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21747
diff changeset
305 assert_equal([1, 2, 3], l)
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21747
diff changeset
306 enddef
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21747
diff changeset
307
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
308 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
309
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
310 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
311 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
312 enddef
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
313
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
314 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
315 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
316 enddef
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
317
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
318 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
319 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
320 enddef
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
321
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
322 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
323 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
324 RefDefArg = FuncOneDefArg
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
325 RefDefArg()
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
326 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
327 RefDefArg('some')
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
328 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
329
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
330 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
331 RefDef2Arg = FuncTwoDefArg
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
332 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
333 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
334 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
335
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
336 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
337 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
338
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
339 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
340 RefVarargs = FuncVarargs
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
341 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
342 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
343 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
344
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
345 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
346 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
347 enddef
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
348
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
349 " Only varargs
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
350 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
351 return join(args, ',')
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
352 enddef
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
353
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
354 def Test_call_varargs_only()
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
355 assert_equal('', MyVarargsOnly())
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
356 assert_equal('one', MyVarargsOnly('one'))
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
357 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
358 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
359 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
360 enddef
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
361
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 def Test_using_var_as_arg()
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
363 call writefile(['def Func(x: number)', 'let x = 234', 'enddef', 'defcompile'], 'Xdef')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 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
365 call delete('Xdef')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367
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
368 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
369 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
370 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
371
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
372 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
373 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
374 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
375
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
376 def Test_assign_to_argument()
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21347
diff changeset
377 # works for dict and list
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
378 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
379 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
380 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
381 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
382 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
383 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
384
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
385 call CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef', 'defcompile'], 'E1090:')
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
386 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
387
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 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
389 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
390 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
391 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
393 func DefinedLater(arg)
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
394 return a:arg
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
395 endfunc
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
396
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
397 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
398 assert_equal(3, g:SomeFunc('abc'))
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21441
diff changeset
399 assert_fails('NotAFunc()', 'E117:') # comment after call
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
400 assert_fails('g:NotAFunc()', 'E117:')
21439
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
401
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
402 let lines =<< trim END
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
403 vim9script
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
404 def RetNumber(): number
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
405 return 123
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
406 enddef
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
407 let Funcref: func: number = function('RetNumber')
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
408 assert_equal(123, Funcref())
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
409 END
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
410 CheckScriptSuccess(lines)
21441
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
411
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
412 lines =<< trim END
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
413 vim9script
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
414 def RetNumber(): number
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
415 return 123
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
416 enddef
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
417 def Bar(F: func: number): number
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
418 return F()
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
419 enddef
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
420 let Funcref = function('RetNumber')
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
421 assert_equal(123, Bar(Funcref))
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
422 END
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
423 CheckScriptSuccess(lines)
21467
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
424
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
425 lines =<< trim END
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
426 vim9script
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
427 def UseNumber(nr: number)
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
428 echo nr
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
429 enddef
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
430 let Funcref: func(number) = function('UseNumber')
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
431 Funcref(123)
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
432 END
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
433 CheckScriptSuccess(lines)
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
434
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
435 lines =<< trim END
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
436 vim9script
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
437 def UseNumber(nr: number)
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
438 echo nr
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
439 enddef
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
440 let Funcref: func(string) = function('UseNumber')
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
441 END
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
442 CheckScriptFailure(lines, 'E1012: type mismatch, expected func(string) but got func(number)')
21500
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
443
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
444 lines =<< trim END
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
445 vim9script
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
446 def EchoNr(nr = 34)
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
447 g:echo = nr
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
448 enddef
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
449 let Funcref: func(?number) = function('EchoNr')
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
450 Funcref()
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
451 assert_equal(34, g:echo)
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
452 Funcref(123)
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
453 assert_equal(123, g:echo)
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
454 END
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
455 CheckScriptSuccess(lines)
21502
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
456
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
457 lines =<< trim END
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
458 vim9script
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
459 def EchoList(...l: list<number>)
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
460 g:echo = l
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
461 enddef
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
462 let Funcref: func(...list<number>) = function('EchoList')
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
463 Funcref()
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
464 assert_equal([], g:echo)
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
465 Funcref(1, 2, 3)
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
466 assert_equal([1, 2, 3], g:echo)
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
467 END
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
468 CheckScriptSuccess(lines)
21504
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
469
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
470 lines =<< trim END
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
471 vim9script
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
472 def OptAndVar(nr: number, opt = 12, ...l: list<number>): number
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
473 g:optarg = opt
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
474 g:listarg = l
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
475 return nr
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
476 enddef
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
477 let Funcref: func(number, ?number, ...list<number>): number = function('OptAndVar')
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
478 assert_equal(10, Funcref(10))
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
479 assert_equal(12, g:optarg)
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
480 assert_equal([], g:listarg)
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
481
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
482 assert_equal(11, Funcref(11, 22))
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
483 assert_equal(22, g:optarg)
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
484 assert_equal([], g:listarg)
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
485
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
486 assert_equal(17, Funcref(17, 18, 1, 2, 3))
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
487 assert_equal(18, g:optarg)
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
488 assert_equal([1, 2, 3], g:listarg)
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
489 END
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
490 CheckScriptSuccess(lines)
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
491 enddef
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
492
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
493 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
494 let NotAFunc = 'text'
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
495
19993
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
496 def CombineFuncrefTypes()
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21347
diff changeset
497 # same arguments, different return type
19993
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
498 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
499 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
500 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
501 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
502
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21347
diff changeset
503 # different number of arguments
19993
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
504 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
505 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
506 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
507 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
508
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21347
diff changeset
509 # different argument types
19993
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
510 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
511 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
512 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
513 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
514 enddef
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
515
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 def FuncWithForwardCall()
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
517 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
518 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 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
521 return arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 def Test_error_in_nested_function()
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21347
diff changeset
525 # Error in called function requires unwinding the call stack.
21160
1a393685e7ce patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents: 21118
diff changeset
526 assert_fails('call FuncWithForwardCall()', 'E1096')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 def Test_return_type_wrong()
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
530 CheckScriptFailure([
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
531 'def Func(): number',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
532 'return "a"',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
533 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
534 'defcompile'], 'expected number but got string')
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
535 CheckScriptFailure([
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
536 'def Func(): string',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
537 'return 1',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
538 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
539 'defcompile'], 'expected string but got number')
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
540 CheckScriptFailure([
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
541 'def Func(): void',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
542 'return "a"',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
543 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
544 'defcompile'],
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
545 'E1096: Returning a value in a function without a return type')
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
546 CheckScriptFailure([
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
547 'def Func()',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
548 'return "a"',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
549 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
550 'defcompile'],
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
551 'E1096: Returning a value in a function without a return type')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
553 CheckScriptFailure([
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
554 'def Func(): number',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
555 'return',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
556 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
557 'defcompile'], 'E1003:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 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
560 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
561 CheckScriptFailure(['def Func()', 'return 1'], 'E1057:')
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
562
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
563 CheckScriptFailure([
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
564 'vim9script',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
565 'def FuncB()',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
566 ' return 123',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
567 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
568 'def FuncA()',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
569 ' FuncB()',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
570 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
571 'defcompile'], 'E1096:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 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
575 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
576 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
577 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
578 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
579 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 def Test_vim9script_call()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 let lines =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 vim9script
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 let var = ''
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 def MyFunc(arg: string)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 var = arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 MyFunc('foobar')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 assert_equal('foobar', var)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 let str = 'barfoo'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 str->MyFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 assert_equal('barfoo', var)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594
20945
0653b9b72091 patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents: 20909
diff changeset
595 g:value = 'value'
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 g:value->MyFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 assert_equal('value', var)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 let listvar = []
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 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
601 listvar = arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 [1, 2, 3]->ListFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 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
605
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 let dictvar = {}
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 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
608 dictvar = arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 {'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
611 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
612 def CompiledDict()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 {'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
614 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 CompiledDict()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 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
617
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 #{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
619 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
620
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 ('text')->MyFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 assert_equal('text', var)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 ("some")->MyFunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 assert_equal('some', var)
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
625
21475
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
626 # line starting with single quote is not a mark
21544
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
627 # line starting with double quote can be a method call
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
628 'asdfasdf'->MyFunc()
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
629 assert_equal('asdfasdf', var)
21544
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
630 "xyz"->MyFunc()
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
631 assert_equal('xyz', var)
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
632
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
633 def UseString()
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
634 'xyork'->MyFunc()
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
635 enddef
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
636 UseString()
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
637 assert_equal('xyork', var)
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
638
21544
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
639 def UseString2()
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
640 "knife"->MyFunc()
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
641 enddef
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
642 UseString2()
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
643 assert_equal('knife', var)
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
644
21475
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
645 # prepending a colon makes it a mark
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
646 new
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
647 setline(1, ['aaa', 'bbb', 'ccc'])
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
648 normal! 3Gmt1G
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
649 :'t
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
650 assert_equal(3, getcurpos()[1])
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
651 bwipe!
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
652
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
653 MyFunc(
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
654 'continued'
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
655 )
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
656 assert_equal('continued',
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
657 var
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
658 )
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
659
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
660 call MyFunc(
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
661 'more'
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
662 ..
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
663 'lines'
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
664 )
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
665 assert_equal(
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
666 'morelines',
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
667 var)
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 writefile(lines, 'Xcall.vim')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 source Xcall.vim
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 delete('Xcall.vim')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 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
675 let lines =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 vim9script
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 let var = ''
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 def MyFunc(arg: string)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 let var = 123
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 enddef
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
681 defcompile
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 END
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21441
diff changeset
683 CheckScriptFailure(lines, 'E1054:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685
21383
f25d007f90ac patch 8.2.1242: Vim9: no error if calling a function with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
686 def Test_vim9script_call_fail_type()
f25d007f90ac patch 8.2.1242: Vim9: no error if calling a function with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
687 let lines =<< trim END
f25d007f90ac patch 8.2.1242: Vim9: no error if calling a function with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
688 vim9script
f25d007f90ac patch 8.2.1242: Vim9: no error if calling a function with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
689 def MyFunc(arg: string)
f25d007f90ac patch 8.2.1242: Vim9: no error if calling a function with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
690 echo arg
f25d007f90ac patch 8.2.1242: Vim9: no error if calling a function with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
691 enddef
f25d007f90ac patch 8.2.1242: Vim9: no error if calling a function with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
692 MyFunc(1234)
f25d007f90ac patch 8.2.1242: Vim9: no error if calling a function with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
693 END
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
694 CheckScriptFailure(lines, 'E1012: type mismatch, expected string but got number')
21383
f25d007f90ac patch 8.2.1242: Vim9: no error if calling a function with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
695 enddef
f25d007f90ac patch 8.2.1242: Vim9: no error if calling a function with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
696
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 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
698 let lines =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 vim9script
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 const var = ''
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 def MyFunc(arg: string)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 var = 'asdf'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 enddef
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
704 defcompile
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 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
707 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
708 delete('Xcall_const.vim')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 " 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
712 " recognized.
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 func Test_function_python()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 CheckFeature python3
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 let py = 'python3'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 execute py "<< EOF"
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 def do_something():
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 return 1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 EOF
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 def Test_delfunc()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 let lines =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 vim9script
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
725 def g:GoneSoon()
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 echo 'hello'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 def CallGoneSoon()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 GoneSoon()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 enddef
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
732 defcompile
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
734 delfunc g:GoneSoon
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 CallGoneSoon()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 writefile(lines, 'XToDelFunc')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 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
739 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
740
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 delete('XToDelFunc')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 def Test_redef_failure()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 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
746 so Xdef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 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
748 so Xdef
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
749 call writefile(['def! Func0(): string', 'enddef', 'defcompile'], 'Xdef')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 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
751 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
752 so Xdef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 call delete('Xdef')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
755 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
756 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
757 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
758
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 delfunc! Func0
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 delfunc! Func1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 delfunc! Func2
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
764 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
765 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
766 vim9script
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
767 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
768 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
769 endfunc
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
770 Func('text')
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
771 END
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
772 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
773 so XVim9Func
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
774
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
775 delete('XVim9Func')
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
776 enddef
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
777
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 " 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
779 func Test_InternalFuncRetType()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 let lines =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 def RetFloat(): float
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 return ceil(1.456)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 def RetListAny(): list<any>
21759
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21751
diff changeset
786 return items({'k': 'v'})
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 def RetListString(): list<string>
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 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
791 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 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
794 return getbufinfo()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 def RetDictNumber(): dict<number>
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 return wordcount()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 def RetDictString(): dict<string>
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 return environ()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 call writefile(lines, 'Xscript')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 source Xscript
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 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
809 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
810 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
811 call assert_notequal([], RetListDictAny())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 call assert_notequal({}, RetDictNumber())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 call assert_notequal({}, RetDictString())
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 call delete('Xscript')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 " 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
818 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
819 let l =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 def! FArgErr(): float
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 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
822 enddef
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
823 defcompile
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 call writefile(l, 'Xinvalidarg')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 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
827 let l =<< trim END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 def! FArgErr(): float
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 return ceil()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 enddef
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
831 defcompile
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 call writefile(l, 'Xinvalidarg')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 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
835 call delete('Xinvalidarg')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 let s:funcResult = 0
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 def FuncNoArgNoRet()
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
841 s:funcResult = 11
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 def FuncNoArgRetNumber(): number
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
845 s:funcResult = 22
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 return 1234
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
849 def FuncNoArgRetString(): string
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
850 s:funcResult = 45
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
851 return 'text'
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
852 enddef
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
853
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 def FuncOneArgNoRet(arg: number)
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
855 s:funcResult = arg
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 def FuncOneArgRetNumber(arg: number): number
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
859 s:funcResult = arg
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 return arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862
19985
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
863 def FuncTwoArgNoRet(one: bool, two: number)
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
864 s:funcResult = two
19985
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
865 enddef
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
866
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
867 def FuncOneArgRetString(arg: string): string
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
868 return arg
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
869 enddef
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
870
19926
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
871 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
872 return arg
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
873 enddef
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
874
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 def Test_func_type()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 let Ref1: func()
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
877 s:funcResult = 0
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 Ref1 = FuncNoArgNoRet
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 Ref1()
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
880 assert_equal(11, s:funcResult)
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
881
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
882 let Ref2: func
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
883 s:funcResult = 0
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
884 Ref2 = FuncNoArgNoRet
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
885 Ref2()
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
886 assert_equal(11, s:funcResult)
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
887
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
888 s:funcResult = 0
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
889 Ref2 = FuncOneArgNoRet
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
890 Ref2(12)
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
891 assert_equal(12, s:funcResult)
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
892
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
893 s:funcResult = 0
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
894 Ref2 = FuncNoArgRetNumber
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
895 assert_equal(1234, Ref2())
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
896 assert_equal(22, s:funcResult)
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
897
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
898 s:funcResult = 0
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
899 Ref2 = FuncOneArgRetNumber
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
900 assert_equal(13, Ref2(13))
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
901 assert_equal(13, s:funcResult)
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903
21162
3158cc2384cc patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21160
diff changeset
904 def Test_repeat_return_type()
3158cc2384cc patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21160
diff changeset
905 let res = 0
3158cc2384cc patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21160
diff changeset
906 for n in repeat([1], 3)
3158cc2384cc patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21160
diff changeset
907 res += n
3158cc2384cc patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21160
diff changeset
908 endfor
3158cc2384cc patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21160
diff changeset
909 assert_equal(3, res)
21164
4a190861f0cc patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21162
diff changeset
910
4a190861f0cc patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21162
diff changeset
911 res = 0
4a190861f0cc patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21162
diff changeset
912 for n in add([1, 2], 3)
4a190861f0cc patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21162
diff changeset
913 res += n
4a190861f0cc patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21162
diff changeset
914 endfor
4a190861f0cc patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21162
diff changeset
915 assert_equal(6, res)
21162
3158cc2384cc patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21160
diff changeset
916 enddef
3158cc2384cc patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21160
diff changeset
917
21170
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
918 def Test_argv_return_type()
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
919 next fileone filetwo
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
920 let res = ''
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
921 for name in argv()
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
922 res ..= name
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
923 endfor
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
924 assert_equal('fileonefiletwo', res)
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
925 enddef
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
926
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
927 def Test_func_type_part()
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
928 let RefVoid: func: void
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
929 RefVoid = FuncNoArgNoRet
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
930 RefVoid = FuncOneArgNoRet
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
931 CheckDefFailure(['let RefVoid: func: void', 'RefVoid = FuncNoArgRetNumber'], 'E1012: type mismatch, expected func() but got func(): number')
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
932 CheckDefFailure(['let RefVoid: func: void', 'RefVoid = FuncNoArgRetString'], 'E1012: type mismatch, expected func() but got func(): string')
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
933
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
934 let RefAny: func(): any
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
935 RefAny = FuncNoArgRetNumber
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
936 RefAny = FuncNoArgRetString
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
937 CheckDefFailure(['let RefAny: func(): any', 'RefAny = FuncNoArgNoRet'], 'E1012: type mismatch, expected func(): any but got func()')
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
938 CheckDefFailure(['let RefAny: func(): any', 'RefAny = FuncOneArgNoRet'], 'E1012: type mismatch, expected func(): any but got func(number)')
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
939
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
940 let RefNr: func: number
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
941 RefNr = FuncNoArgRetNumber
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
942 RefNr = FuncOneArgRetNumber
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
943 CheckDefFailure(['let RefNr: func: number', 'RefNr = FuncNoArgNoRet'], 'E1012: type mismatch, expected func(): number but got func()')
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
944 CheckDefFailure(['let RefNr: func: number', 'RefNr = FuncNoArgRetString'], 'E1012: type mismatch, expected func(): number but got func(): string')
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
945
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
946 let RefStr: func: string
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
947 RefStr = FuncNoArgRetString
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
948 RefStr = FuncOneArgRetString
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
949 CheckDefFailure(['let RefStr: func: string', 'RefStr = FuncNoArgNoRet'], 'E1012: type mismatch, expected func(): string but got func()')
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
950 CheckDefFailure(['let RefStr: func: string', 'RefStr = FuncNoArgRetNumber'], 'E1012: type mismatch, expected func(): string but got func(): number')
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
951 enddef
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
952
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 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
954 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
955
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
956 CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncNoArgRetNumber'], 'E1012: type mismatch, expected func() but got func(): number')
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
957 CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgNoRet'], 'E1012: type mismatch, expected func() but got func(number)')
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
958 CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgRetNumber'], 'E1012: type mismatch, expected func() but got func(number): number')
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
959 CheckDefFailure(['let Ref1: func(bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1012: type mismatch, expected func(bool) but got func(bool, number)')
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
960 CheckDefFailure(['let Ref1: func(?bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1012: type mismatch, expected func(?bool) but got func(bool, number)')
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
961 CheckDefFailure(['let Ref1: func(...bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1012: type mismatch, expected func(...bool) but got func(bool, number)')
19985
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
962
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
963 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
964 call CheckDefFailure(['let RefWrong: func(string,number)'], 'E1069:')
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
965 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)'], 'E1005:')
19985
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
966 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
967 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968
19926
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
969 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
970 let nr: number
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
971 nr = FuncNoArgRetNumber()
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
972 assert_equal(1234, nr)
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
973
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
974 nr = FuncOneArgRetAny(122)
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
975 assert_equal(122, nr)
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
976
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
977 let str: string
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
978 str = FuncOneArgRetAny('yes')
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
979 assert_equal('yes', str)
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
980
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21795
diff changeset
981 CheckDefFailure(['let str: string', 'str = FuncNoArgRetNumber()'], 'E1012: type mismatch, expected string but got number')
19926
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
982 enddef
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
983
20015
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
984 def MultiLine(
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
985 arg1: string,
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
986 arg2 = 1234,
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
987 ...rest: list<string>
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
988 ): string
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
989 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
990 enddef
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
991
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
992 def MultiLineComment(
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
993 arg1: string, # comment
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
994 arg2 = 1234, # comment
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
995 ...rest: list<string> # comment
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
996 ): string # comment
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
997 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
998 enddef
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
999
20015
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1000 def Test_multiline()
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1001 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
1002 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
1003 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
1004 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
1005 enddef
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1006
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
1007 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
1008 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
1009 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
1010 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
1011 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
1012 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
1013
20015
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1014
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1015 " 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
1016 " of E1056.
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1017 func Test_E1056_1059()
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1018 let caught_1056 = 0
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1019 try
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1020 def F():
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1021 return 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1022 enddef
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1023 catch /E1056:/
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1024 let caught_1056 = 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1025 endtry
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1026 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
1027
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1028 let caught_1059 = 0
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1029 try
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1030 def F5(items : list)
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1031 echo 'a'
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1032 enddef
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1033 catch /E1059:/
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1034 let caught_1059 = 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1035 endtry
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1036 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
1037 endfunc
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1039 func DelMe()
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1040 echo 'DelMe'
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1041 endfunc
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1042
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1043 def Test_error_reporting()
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1044 # comment lines at the start of the function
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1045 let lines =<< trim END
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1046 " comment
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1047 def Func()
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1048 # comment
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1049 # comment
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1050 invalid
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1051 enddef
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1052 defcompile
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1053 END
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1054 call writefile(lines, 'Xdef')
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1055 try
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1056 source Xdef
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1057 assert_report('should have failed')
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1058 catch /E476:/
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1059 assert_match('Invalid command: invalid', v:exception)
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1060 assert_match(', line 3$', v:throwpoint)
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1061 endtry
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1062
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1063 # comment lines after the start of the function
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1064 lines =<< trim END
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1065 " comment
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1066 def Func()
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1067 let x = 1234
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1068 # comment
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1069 # comment
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1070 invalid
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1071 enddef
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1072 defcompile
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1073 END
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1074 call writefile(lines, 'Xdef')
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1075 try
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1076 source Xdef
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1077 assert_report('should have failed')
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1078 catch /E476:/
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1079 assert_match('Invalid command: invalid', v:exception)
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1080 assert_match(', line 4$', v:throwpoint)
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1081 endtry
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1082
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1083 lines =<< trim END
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1084 vim9script
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1085 def Func()
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1086 let db = #{foo: 1, bar: 2}
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1087 # comment
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1088 let x = db.asdf
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1089 enddef
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1090 defcompile
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1091 Func()
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1092 END
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1093 call writefile(lines, 'Xdef')
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1094 try
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1095 source Xdef
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1096 assert_report('should have failed')
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1097 catch /E716:/
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1098 assert_match('_Func, line 3$', v:throwpoint)
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1099 endtry
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1100
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1101 call delete('Xdef')
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1102 enddef
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1103
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1104 def Test_deleted_function()
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1105 CheckDefExecFailure([
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1106 '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
1107 'delfunc g:DelMe',
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1108 'echo RefMe()'], 'E117:')
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1109 enddef
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1110
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1111 def Test_unknown_function()
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1112 CheckDefExecFailure([
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1113 'let Ref: func = function("NotExist")',
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21263
diff changeset
1114 'delfunc g:NotExist'], 'E700:')
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1115 enddef
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1116
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1117 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
1118 return Ref('more')
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1119 enddef
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1120
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1121 def Test_closure_simple()
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1122 let local = 'some '
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1123 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
1124 enddef
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1125
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1126 def MakeRef()
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1127 let local = 'some '
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1128 g:Ref = {s -> local .. s}
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1129 enddef
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1130
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1131 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
1132 MakeRef()
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1133 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
1134 unlet g:Ref
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1135 enddef
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1136
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1137 def MakeTwoRefs()
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1138 let local = ['some']
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1139 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
1140 g:Read = {-> local}
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1141 enddef
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1142
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1143 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
1144 MakeTwoRefs()
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1145 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
1146 g:Extend('more')
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1147 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
1148 g:Extend('even')
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1149 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
1150
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1151 unlet g:Extend
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1152 unlet g:Read
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1153 enddef
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1154
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1155 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
1156 return join(Ref(), ' ')
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1157 enddef
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1158
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1159 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
1160 Ref(add)
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1161 enddef
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1162
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1163 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
1164 MakeTwoRefs()
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1165 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
1166 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
1167 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
1168 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
1169 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
1170
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1171 unlet g:Extend
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1172 unlet g:Read
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1173 enddef
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1174
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1175 def MakeArgRefs(theArg: string)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1176 let local = 'loc_val'
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1177 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
1178 enddef
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1179
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1180 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
1181 let local = 'the_loc'
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1182 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
1183 enddef
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1184
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1185 def Test_closure_using_argument()
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1186 MakeArgRefs('arg_val')
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1187 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
1188
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1189 MakeArgRefsVarargs('arg_val', 'one', 'two')
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1190 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
1191
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1192 unlet g:UseArg
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1193 unlet g:UseVararg
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1194 enddef
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1195
20295
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1196 def MakeGetAndAppendRefs()
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1197 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
1198
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1199 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
1200 local ..= arg
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1201 enddef
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1202 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
1203
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1204 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
1205 return local
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1206 enddef
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1207 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
1208 enddef
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1209
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1210 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
1211 MakeGetAndAppendRefs()
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1212 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
1213 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
1214 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
1215 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
1216 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
1217
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1218 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
1219 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
1220 enddef
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1221
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
1222 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
1223 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
1224 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
1225 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
1226 enddef
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
1227 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
1228 enddef
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
1229
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
1230 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
1231 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
1232 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
1233
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20355
diff changeset
1234 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
1235 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
1236 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
1237 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
1238 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
1239
20903
54ffae914876 patch 8.2.1003: Vim9: return type of sort() is too generic
Bram Moolenaar <Bram@vim.org>
parents: 20532
diff changeset
1240 def Test_sort_return_type()
54ffae914876 patch 8.2.1003: Vim9: return type of sort() is too generic
Bram Moolenaar <Bram@vim.org>
parents: 20532
diff changeset
1241 let res: list<number>
54ffae914876 patch 8.2.1003: Vim9: return type of sort() is too generic
Bram Moolenaar <Bram@vim.org>
parents: 20532
diff changeset
1242 res = [1, 2, 3]->sort()
54ffae914876 patch 8.2.1003: Vim9: return type of sort() is too generic
Bram Moolenaar <Bram@vim.org>
parents: 20532
diff changeset
1243 enddef
54ffae914876 patch 8.2.1003: Vim9: return type of sort() is too generic
Bram Moolenaar <Bram@vim.org>
parents: 20532
diff changeset
1244
21089
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1245 def Test_getqflist_return_type()
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1246 let l = getqflist()
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1247 assert_equal([], l)
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1248
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1249 let d = getqflist(#{items: 0})
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1250 assert_equal(#{items: []}, d)
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1251 enddef
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1252
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1253 def Test_getloclist_return_type()
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1254 let l = getloclist(1)
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1255 assert_equal([], l)
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1256
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1257 let d = getloclist(1, #{items: 0})
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1258 assert_equal(#{items: []}, d)
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1259 enddef
d69ead03ba93 patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
1260
21174
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1261 def Test_copy_return_type()
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1262 let l = copy([1, 2, 3])
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1263 let res = 0
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1264 for n in l
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1265 res += n
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1266 endfor
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1267 assert_equal(6, res)
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1268
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1269 let dl = deepcopy([1, 2, 3])
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1270 res = 0
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1271 for n in dl
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1272 res += n
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1273 endfor
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1274 assert_equal(6, res)
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1275 enddef
95abb4b22905 patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
1276
21178
fab2085e417f patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents: 21176
diff changeset
1277 def Test_extend_return_type()
fab2085e417f patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents: 21176
diff changeset
1278 let l = extend([1, 2], [3])
fab2085e417f patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents: 21176
diff changeset
1279 let res = 0
fab2085e417f patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents: 21176
diff changeset
1280 for n in l
fab2085e417f patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents: 21176
diff changeset
1281 res += n
fab2085e417f patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents: 21176
diff changeset
1282 endfor
fab2085e417f patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents: 21176
diff changeset
1283 assert_equal(6, res)
fab2085e417f patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents: 21176
diff changeset
1284 enddef
fab2085e417f patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents: 21176
diff changeset
1285
21182
7289c8b9a620 patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents: 21180
diff changeset
1286 def Test_insert_return_type()
7289c8b9a620 patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents: 21180
diff changeset
1287 let l = insert([2, 1], 3)
7289c8b9a620 patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents: 21180
diff changeset
1288 let res = 0
7289c8b9a620 patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents: 21180
diff changeset
1289 for n in l
7289c8b9a620 patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents: 21180
diff changeset
1290 res += n
7289c8b9a620 patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents: 21180
diff changeset
1291 endfor
7289c8b9a620 patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents: 21180
diff changeset
1292 assert_equal(6, res)
7289c8b9a620 patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents: 21180
diff changeset
1293 enddef
7289c8b9a620 patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents: 21180
diff changeset
1294
21795
51d4e0bc2eb7 patch 8.2.1447: Vim9: return type of keys() is list<any>
Bram Moolenaar <Bram@vim.org>
parents: 21793
diff changeset
1295 def Test_keys_return_type()
51d4e0bc2eb7 patch 8.2.1447: Vim9: return type of keys() is list<any>
Bram Moolenaar <Bram@vim.org>
parents: 21793
diff changeset
1296 const var: list<string> = #{a: 1, b: 2}->keys()
51d4e0bc2eb7 patch 8.2.1447: Vim9: return type of keys() is list<any>
Bram Moolenaar <Bram@vim.org>
parents: 21793
diff changeset
1297 assert_equal(['a', 'b'], var)
51d4e0bc2eb7 patch 8.2.1447: Vim9: return type of keys() is list<any>
Bram Moolenaar <Bram@vim.org>
parents: 21793
diff changeset
1298 enddef
51d4e0bc2eb7 patch 8.2.1447: Vim9: return type of keys() is list<any>
Bram Moolenaar <Bram@vim.org>
parents: 21793
diff changeset
1299
21186
34667dc9207b patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents: 21184
diff changeset
1300 def Test_reverse_return_type()
34667dc9207b patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents: 21184
diff changeset
1301 let l = reverse([1, 2, 3])
34667dc9207b patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents: 21184
diff changeset
1302 let res = 0
34667dc9207b patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents: 21184
diff changeset
1303 for n in l
34667dc9207b patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents: 21184
diff changeset
1304 res += n
34667dc9207b patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents: 21184
diff changeset
1305 endfor
34667dc9207b patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents: 21184
diff changeset
1306 assert_equal(6, res)
34667dc9207b patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents: 21184
diff changeset
1307 enddef
34667dc9207b patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents: 21184
diff changeset
1308
21184
2113e94dc726 patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents: 21182
diff changeset
1309 def Test_remove_return_type()
2113e94dc726 patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents: 21182
diff changeset
1310 let l = remove(#{one: [1, 2], two: [3, 4]}, 'one')
2113e94dc726 patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents: 21182
diff changeset
1311 let res = 0
2113e94dc726 patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents: 21182
diff changeset
1312 for n in l
2113e94dc726 patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents: 21182
diff changeset
1313 res += n
2113e94dc726 patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents: 21182
diff changeset
1314 endfor
2113e94dc726 patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents: 21182
diff changeset
1315 assert_equal(3, res)
2113e94dc726 patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents: 21182
diff changeset
1316 enddef
2113e94dc726 patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents: 21182
diff changeset
1317
21180
dde4c2e84f5c patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents: 21178
diff changeset
1318 def Test_filter_return_type()
dde4c2e84f5c patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents: 21178
diff changeset
1319 let l = filter([1, 2, 3], {-> 1})
dde4c2e84f5c patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents: 21178
diff changeset
1320 let res = 0
dde4c2e84f5c patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents: 21178
diff changeset
1321 for n in l
dde4c2e84f5c patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents: 21178
diff changeset
1322 res += n
dde4c2e84f5c patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents: 21178
diff changeset
1323 endfor
dde4c2e84f5c patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents: 21178
diff changeset
1324 assert_equal(6, res)
dde4c2e84f5c patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents: 21178
diff changeset
1325 enddef
dde4c2e84f5c patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents: 21178
diff changeset
1326
21855
c8456ff7a4c3 patch 8.2.1477: Vim9: error when using bufnr('%')
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
1327 def Test_bufnr()
c8456ff7a4c3 patch 8.2.1477: Vim9: error when using bufnr('%')
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
1328 let buf = bufnr()
c8456ff7a4c3 patch 8.2.1477: Vim9: error when using bufnr('%')
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
1329 assert_equal(buf, bufnr('%'))
c8456ff7a4c3 patch 8.2.1477: Vim9: error when using bufnr('%')
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
1330 enddef
c8456ff7a4c3 patch 8.2.1477: Vim9: error when using bufnr('%')
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
1331
21899
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21879
diff changeset
1332 def Test_col()
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21879
diff changeset
1333 new
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21879
diff changeset
1334 setline(1, 'asdf')
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21879
diff changeset
1335 assert_equal(5, col([1, '$']))
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21879
diff changeset
1336 enddef
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21879
diff changeset
1337
21660
9a2ce62b93e9 patch 8.2.1380: Vim9: return type of getreg() is always a string
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
1338 def Test_getreg_return_type()
9a2ce62b93e9 patch 8.2.1380: Vim9: return type of getreg() is always a string
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
1339 let s1: string = getreg('"')
9a2ce62b93e9 patch 8.2.1380: Vim9: return type of getreg() is always a string
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
1340 let s2: string = getreg('"', 1)
9a2ce62b93e9 patch 8.2.1380: Vim9: return type of getreg() is always a string
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
1341 let s3: list<string> = getreg('"', 1, 1)
9a2ce62b93e9 patch 8.2.1380: Vim9: return type of getreg() is always a string
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
1342 enddef
9a2ce62b93e9 patch 8.2.1380: Vim9: return type of getreg() is always a string
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
1343
21301
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
1344 def Wrong_dict_key_type(items: list<number>): list<number>
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
1345 return filter(items, {_, val -> get({val: 1}, 'x')})
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
1346 enddef
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
1347
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
1348 def Test_wrong_dict_key_type()
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
1349 assert_fails('Wrong_dict_key_type([1, 2, 3])', 'E1029:')
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
1350 enddef
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
1351
20972
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
1352 def Line_continuation_in_def(dir: string = ''): string
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
1353 let path: string = empty(dir)
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
1354 \ ? 'empty'
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
1355 \ : 'full'
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
1356 return path
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
1357 enddef
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
1358
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
1359 def Test_line_continuation_in_def()
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
1360 assert_equal('full', Line_continuation_in_def('.'))
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
1361 enddef
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
1362
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
1363 def Line_continuation_in_lambda(): list<number>
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
1364 let x = range(97, 100)
21263
71bd2f9adb61 patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
1365 ->map({_, v -> nr2char(v)
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
1366 ->toupper()})
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
1367 ->reverse()
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
1368 return x
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
1369 enddef
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
1370
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
1371 def Test_line_continuation_in_lambda()
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
1372 assert_equal(['D', 'C', 'B', 'A'], Line_continuation_in_lambda())
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
1373 enddef
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
1374
21176
54c665ad2db3 patch 8.2.1139: Vim9: test for silent echo fails in some environments
Bram Moolenaar <Bram@vim.org>
parents: 21174
diff changeset
1375 func Test_silent_echo()
21172
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1376 CheckScreendump
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1377
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1378 let lines =<< trim END
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1379 vim9script
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1380 def EchoNothing()
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1381 silent echo ''
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1382 enddef
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1383 defcompile
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1384 END
21176
54c665ad2db3 patch 8.2.1139: Vim9: test for silent echo fails in some environments
Bram Moolenaar <Bram@vim.org>
parents: 21174
diff changeset
1385 call writefile(lines, 'XTest_silent_echo')
21172
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1386
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1387 " Check that the balloon shows up after a mouse move
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1388 let buf = RunVimInTerminal('-S XTest_silent_echo', {'rows': 6})
21176
54c665ad2db3 patch 8.2.1139: Vim9: test for silent echo fails in some environments
Bram Moolenaar <Bram@vim.org>
parents: 21174
diff changeset
1389 call term_sendkeys(buf, ":abc")
21172
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1390 call VerifyScreenDump(buf, 'Test_vim9_silent_echo', {})
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1391
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1392 " clean up
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1393 call StopVimInTerminal(buf)
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1394 call delete('XTest_silent_echo')
21176
54c665ad2db3 patch 8.2.1139: Vim9: test for silent echo fails in some environments
Bram Moolenaar <Bram@vim.org>
parents: 21174
diff changeset
1395 endfunc
21172
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
1396
21861
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21855
diff changeset
1397 def Test_search()
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21855
diff changeset
1398 new
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21855
diff changeset
1399 setline(1, ['foo', 'bar'])
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21855
diff changeset
1400 let val = 0
21913
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
1401 # skip expr returns boolean
21861
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21855
diff changeset
1402 assert_equal(2, search('bar', 'W', 0, 0, {-> val == 1}))
21913
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
1403 :1
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
1404 assert_equal(0, search('bar', 'W', 0, 0, {-> val == 0}))
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
1405 # skip expr returns number, only 0 and 1 are accepted
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
1406 :1
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
1407 assert_equal(2, search('bar', 'W', 0, 0, {-> 0}))
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
1408 :1
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
1409 assert_equal(0, search('bar', 'W', 0, 0, {-> 1}))
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
1410 assert_fails("search('bar', '', 0, 0, {-> -1})", 'E1023:')
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
1411 assert_fails("search('bar', '', 0, 0, {-> -1})", 'E1023:')
21861
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21855
diff changeset
1412 enddef
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21855
diff changeset
1413
21873
62e61424482f patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents: 21871
diff changeset
1414 def Test_readdir()
21913
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
1415 eval expand('sautest')->readdir({e -> e[0] !=# '.'})
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
1416 eval expand('sautest')->readdirex({e -> e.name[0] !=# '.'})
21871
e27555ca1093 patch 8.2.1485: Vim9: readdirex() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
1417 enddef
e27555ca1093 patch 8.2.1485: Vim9: readdirex() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
1418
21879
172b1746489c patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents: 21873
diff changeset
1419 def Test_setbufvar()
172b1746489c patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents: 21873
diff changeset
1420 setbufvar(bufnr('%'), '&syntax', 'vim')
172b1746489c patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents: 21873
diff changeset
1421 assert_equal('vim', &syntax)
172b1746489c patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents: 21873
diff changeset
1422 setbufvar(bufnr('%'), '&ts', 16)
172b1746489c patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents: 21873
diff changeset
1423 assert_equal(16, &ts)
172b1746489c patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents: 21873
diff changeset
1424 settabwinvar(1, 1, '&syntax', 'vam')
172b1746489c patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents: 21873
diff changeset
1425 assert_equal('vam', &syntax)
172b1746489c patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents: 21873
diff changeset
1426 settabwinvar(1, 1, '&ts', 15)
172b1746489c patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents: 21873
diff changeset
1427 assert_equal(15, &ts)
172b1746489c patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents: 21873
diff changeset
1428 setlocal ts=8
172b1746489c patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents: 21873
diff changeset
1429 enddef
172b1746489c patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents: 21873
diff changeset
1430
21967
bf68435a695a patch 8.2.1533: Vim9: error when passing getreginfo() result to setreg()
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
1431 def Test_setreg()
bf68435a695a patch 8.2.1533: Vim9: error when passing getreginfo() result to setreg()
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
1432 setreg('a', ['aaa', 'bbb', 'ccc'])
bf68435a695a patch 8.2.1533: Vim9: error when passing getreginfo() result to setreg()
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
1433 let reginfo = getreginfo('a')
bf68435a695a patch 8.2.1533: Vim9: error when passing getreginfo() result to setreg()
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
1434 setreg('a', reginfo)
bf68435a695a patch 8.2.1533: Vim9: error when passing getreginfo() result to setreg()
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
1435 assert_equal(reginfo, getreginfo('a'))
bf68435a695a patch 8.2.1533: Vim9: error when passing getreginfo() result to setreg()
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
1436 enddef
bf68435a695a patch 8.2.1533: Vim9: error when passing getreginfo() result to setreg()
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
1437
21281
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
1438 def Fibonacci(n: number): number
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
1439 if n < 2
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
1440 return n
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
1441 else
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
1442 return Fibonacci(n - 1) + Fibonacci(n - 2)
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
1443 endif
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
1444 enddef
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
1445
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
1446 def Test_recursive_call()
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
1447 assert_equal(6765, Fibonacci(20))
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
1448 enddef
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
1449
21303
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1450 def TreeWalk(dir: string): list<any>
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1451 return readdir(dir)->map({_, val ->
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1452 fnamemodify(dir .. '/' .. val, ':p')->isdirectory()
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
1453 ? {val: TreeWalk(dir .. '/' .. val)}
21303
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1454 : val
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1455 })
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1456 enddef
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1457
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1458 def Test_closure_in_map()
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1459 mkdir('XclosureDir/tdir', 'p')
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1460 writefile(['111'], 'XclosureDir/file1')
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1461 writefile(['222'], 'XclosureDir/file2')
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1462 writefile(['333'], 'XclosureDir/tdir/file3')
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1463
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1464 assert_equal(['file1', 'file2', {'tdir': ['file3']}], TreeWalk('XclosureDir'))
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1465
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1466 delete('XclosureDir', 'rf')
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1467 enddef
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
1468
21347
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1469 def Test_partial_call()
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1470 let Xsetlist = function('setloclist', [0])
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1471 Xsetlist([], ' ', {'title': 'test'})
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1472 assert_equal({'title': 'test'}, getloclist(0, {'title': 1}))
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1473
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1474 Xsetlist = function('setloclist', [0, [], ' '])
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1475 Xsetlist({'title': 'test'})
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1476 assert_equal({'title': 'test'}, getloclist(0, {'title': 1}))
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1477
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1478 Xsetlist = function('setqflist')
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1479 Xsetlist([], ' ', {'title': 'test'})
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1480 assert_equal({'title': 'test'}, getqflist({'title': 1}))
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1481
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1482 Xsetlist = function('setqflist', [[], ' '])
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1483 Xsetlist({'title': 'test'})
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1484 assert_equal({'title': 'test'}, getqflist({'title': 1}))
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1485 enddef
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
1486
21689
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1487 def Test_cmd_modifier()
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1488 tab echo '0'
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1489 call CheckDefFailure(['5tab echo 3'], 'E16:')
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1490 enddef
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1491
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1492 def Test_restore_modifiers()
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1493 # check that when compiling a :def function command modifiers are not messed
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1494 # up.
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1495 let lines =<< trim END
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1496 vim9script
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1497 set eventignore=
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1498 autocmd QuickFixCmdPost * copen
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1499 def AutocmdsDisabled()
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1500 eval 0
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1501 enddef
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1502 func Func()
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1503 noautocmd call s:AutocmdsDisabled()
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1504 let g:ei_after = &eventignore
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1505 endfunc
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1506 Func()
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1507 END
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1508 CheckScriptSuccess(lines)
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1509 assert_equal('', g:ei_after)
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1510 enddef
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
1511
20257
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20255
diff changeset
1512
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker