annotate src/testdir/test_vim9_func.vim @ 24695:13efbfc53054 v8.2.2886

patch 8.2.2886: various pieces of code not covered by tests Commit: https://github.com/vim/vim/commit/34fcb697240c1bc9e69417ed75db3b1a83479724 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Tue May 25 20:14:00 2021 +0200 patch 8.2.2886: various pieces of code not covered by tests Problem: Various pieces of code not covered by tests. Solution: Add a few more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/8255)
author Bram Moolenaar <Bram@vim.org>
date Tue, 25 May 2021 20:15:03 +0200
parents 04205b7d67d5
children 7464d4c927f5
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
22155
de47cb7b41e6 patch 8.2.1627: Vim9: cannot pass "true" to submatch/term_gettty/term_start
Bram Moolenaar <Bram@vim.org>
parents: 22149
diff changeset
4 source term_util.vim
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 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
6 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
7 source screendump.vim
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 func Test_def_basic()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 def SomeFunc(): string
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 return 'yes'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 enddef
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
13 call SomeFunc()->assert_equal('yes')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
22586
622294200ccd patch 8.2.1841: Vim9: test for compilation error fails in normal build
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
16 func Test_compiling_error()
622294200ccd patch 8.2.1841: Vim9: test for compilation error fails in normal build
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
17 " use a terminal to see the whole error message
22584
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
18 CheckRunVimInTerminal
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
19
22586
622294200ccd patch 8.2.1841: Vim9: test for compilation error fails in normal build
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
20 call TestCompilingError()
24369
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
21 call TestCompilingErrorInTry()
22586
622294200ccd patch 8.2.1841: Vim9: test for compilation error fails in normal build
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
22 endfunc
622294200ccd patch 8.2.1841: Vim9: test for compilation error fails in normal build
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
23
622294200ccd patch 8.2.1841: Vim9: test for compilation error fails in normal build
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
24 def TestCompilingError()
22584
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
25 var lines =<< trim END
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
26 vim9script
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
27 def Fails()
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
28 echo nothing
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
29 enddef
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
30 defcompile
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
31 END
24369
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
32 writefile(lines, 'XTest_compile_error')
22584
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
33 var buf = RunVimInTerminal('-S XTest_compile_error',
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
34 {rows: 10, wait_for_ruler: 0})
24369
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
35 WaitForAssert(() => assert_match('Error detected while compiling command line.*Fails.*Variable not found: nothing',
23940
949238ccbd50 patch 8.2.2512: Vim9: compiling error test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents: 23925
diff changeset
36 Term_getlines(buf, range(1, 9))))
22584
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
37
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
38 # clean up
24369
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
39 StopVimInTerminal(buf)
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
40 delete('XTest_compile_error')
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
41 enddef
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
42
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
43 def TestCompilingErrorInTry()
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
44 var dir = 'Xdir/autoload'
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
45 mkdir(dir, 'p')
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
46
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
47 var lines =<< trim END
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
48 vim9script
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
49 def script#OnlyCompiled()
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
50 g:runtime = 'yes'
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
51 invalid
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
52 enddef
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
53 END
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
54 writefile(lines, dir .. '/script.vim')
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
55
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
56 lines =<< trim END
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
57 vim9script
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
58 todo
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
59 try
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
60 script#OnlyCompiled()
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
61 catch /nothing/
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
62 endtry
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
63 END
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
64 lines[1] = 'set rtp=' .. getcwd() .. '/Xdir'
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
65 writefile(lines, 'XTest_compile_error')
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
66
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
67 var buf = RunVimInTerminal('-S XTest_compile_error', {rows: 10, wait_for_ruler: 0})
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
68 WaitForAssert(() => assert_match('Error detected while compiling command line.*function script#OnlyCompiled.*Invalid command: invalid',
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
69 Term_getlines(buf, range(1, 9))))
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
70
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
71 # clean up
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
72 StopVimInTerminal(buf)
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
73 delete('XTest_compile_error')
a97fb00978f6 patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch
Bram Moolenaar <Bram@vim.org>
parents: 24355
diff changeset
74 delete('Xdir', 'rf')
22584
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
75 enddef
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
76
24436
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
77 def Test_autoload_name_mismatch()
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
78 var dir = 'Xdir/autoload'
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
79 mkdir(dir, 'p')
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
80
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
81 var lines =<< trim END
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
82 vim9script
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
83 def scriptX#Function()
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
84 # comment
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
85 g:runtime = 'yes'
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
86 enddef
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
87 END
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
88 writefile(lines, dir .. '/script.vim')
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
89
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
90 var save_rtp = &rtp
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
91 exe 'set rtp=' .. getcwd() .. '/Xdir'
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
92 lines =<< trim END
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
93 call script#Function()
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
94 END
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
95 CheckScriptFailure(lines, 'E746:', 2)
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
96
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
97 &rtp = save_rtp
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
98 delete(dir, 'rf')
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
99 enddef
ccdd5e9a3763 patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
100
22908
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
101 def CallRecursive(n: number): number
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
102 return CallRecursive(n + 1)
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
103 enddef
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
104
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
105 def CallMapRecursive(l: list<number>): number
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
106 return map(l, (_, v) => CallMapRecursive([v]))[0]
22908
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
107 enddef
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
108
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
109 def Test_funcdepth_error()
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
110 set maxfuncdepth=10
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
111
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
112 var caught = false
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
113 try
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
114 CallRecursive(1)
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
115 catch /E132:/
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
116 caught = true
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
117 endtry
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
118 assert_true(caught)
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
119
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
120 caught = false
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
121 try
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
122 CallMapRecursive([1])
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
123 catch /E132:/
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
124 caught = true
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
125 endtry
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
126 assert_true(caught)
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
127
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
128 set maxfuncdepth&
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
129 enddef
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
130
23442
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
131 def Test_endfunc_enddef()
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
132 var lines =<< trim END
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
133 def Test()
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
134 echo 'test'
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
135 endfunc
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
136 enddef
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
137 END
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
138 CheckScriptFailure(lines, 'E1151:', 3)
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
139
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
140 lines =<< trim END
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
141 def Test()
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
142 func Nested()
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
143 echo 'test'
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
144 enddef
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
145 enddef
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
146 END
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
147 CheckScriptFailure(lines, 'E1152:', 4)
24208
7a21b2581dce patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 24156
diff changeset
148
7a21b2581dce patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 24156
diff changeset
149 lines =<< trim END
7a21b2581dce patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 24156
diff changeset
150 def Ok()
7a21b2581dce patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 24156
diff changeset
151 echo 'hello'
7a21b2581dce patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 24156
diff changeset
152 enddef | echo 'there'
7a21b2581dce patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 24156
diff changeset
153 def Bad()
7a21b2581dce patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 24156
diff changeset
154 echo 'hello'
7a21b2581dce patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 24156
diff changeset
155 enddef there
7a21b2581dce patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 24156
diff changeset
156 END
7a21b2581dce patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 24156
diff changeset
157 CheckScriptFailure(lines, 'E1173: Text found after enddef: there', 6)
23442
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
158 enddef
f00d6ff51046 patch 8.2.2264: Vim9: no error for mismatched :endfunc or :enddef
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
159
23444
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
160 def Test_missing_endfunc_enddef()
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
161 var lines =<< trim END
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
162 vim9script
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
163 def Test()
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
164 echo 'test'
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
165 endef
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
166 END
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
167 CheckScriptFailure(lines, 'E1057:', 2)
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
168
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
169 lines =<< trim END
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
170 vim9script
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
171 func Some()
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
172 echo 'test'
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
173 enfffunc
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
174 END
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
175 CheckScriptFailure(lines, 'E126:', 2)
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
176 enddef
7278e86c2f70 patch 8.2.2265: error message for missing endfunc/enddef is last line
Bram Moolenaar <Bram@vim.org>
parents: 23442
diff changeset
177
23727
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
178 def Test_white_space_before_paren()
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
179 var lines =<< trim END
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
180 vim9script
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
181 def Test ()
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
182 echo 'test'
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
183 enddef
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
184 END
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
185 CheckScriptFailure(lines, 'E1068:', 2)
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
186
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
187 lines =<< trim END
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
188 vim9script
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
189 func Test ()
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
190 echo 'test'
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
191 endfunc
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
192 END
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
193 CheckScriptFailure(lines, 'E1068:', 2)
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
194
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
195 lines =<< trim END
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
196 def Test ()
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
197 echo 'test'
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
198 enddef
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
199 END
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
200 CheckScriptFailure(lines, 'E1068:', 1)
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
201
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
202 lines =<< trim END
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
203 func Test ()
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
204 echo 'test'
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
205 endfunc
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
206 END
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
207 CheckScriptSuccess(lines)
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
208 enddef
7d0959080545 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
209
23545
987fb6e8a376 patch 8.2.2315: Vim9: "enddef" as dict key misintepreted as function end
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
210 def Test_enddef_dict_key()
987fb6e8a376 patch 8.2.2315: Vim9: "enddef" as dict key misintepreted as function end
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
211 var d = {
987fb6e8a376 patch 8.2.2315: Vim9: "enddef" as dict key misintepreted as function end
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
212 enddef: 'x',
987fb6e8a376 patch 8.2.2315: Vim9: "enddef" as dict key misintepreted as function end
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
213 endfunc: 'y',
987fb6e8a376 patch 8.2.2315: Vim9: "enddef" as dict key misintepreted as function end
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
214 }
987fb6e8a376 patch 8.2.2315: Vim9: "enddef" as dict key misintepreted as function end
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
215 assert_equal({enddef: 'x', endfunc: 'y'}, d)
987fb6e8a376 patch 8.2.2315: Vim9: "enddef" as dict key misintepreted as function end
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
216 enddef
987fb6e8a376 patch 8.2.2315: Vim9: "enddef" as dict key misintepreted as function end
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
217
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 def ReturnString(): string
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 return 'string'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 def ReturnNumber(): number
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 return 123
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 let g:notNumber = 'string'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 def ReturnGlobal(): number
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 return g:notNumber
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 def Test_return_something()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
233 ReturnString()->assert_equal('string')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
234 ReturnNumber()->assert_equal(123)
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22264
diff changeset
235 assert_fails('ReturnGlobal()', 'E1012: Type mismatch; expected number but got string', '', 1, 'ReturnGlobal')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237
23691
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
238 def Test_check_argument_type()
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
239 var lines =<< trim END
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
240 vim9script
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
241 def Val(a: number, b: number): number
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
242 return 0
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
243 enddef
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
244 def Func()
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
245 var x: any = true
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
246 Val(0, x)
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
247 enddef
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
248 disass Func
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
249 Func()
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
250 END
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
251 CheckScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected number but got bool', 2)
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
252 enddef
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23689
diff changeset
253
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
254 def Test_missing_return()
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
255 CheckDefFailure(['def Missing(): number',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
256 ' if g:cond',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
257 ' echo "no return"',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
258 ' else',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
259 ' return 0',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
260 ' endif'
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
261 'enddef'], 'E1027:')
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
262 CheckDefFailure(['def Missing(): number',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
263 ' if g:cond',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
264 ' return 1',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
265 ' else',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
266 ' echo "no return"',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
267 ' endif'
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
268 'enddef'], 'E1027:')
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
269 CheckDefFailure(['def Missing(): number',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
270 ' if g:cond',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
271 ' return 1',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
272 ' else',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
273 ' return 2',
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
274 ' endif'
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
275 ' return 3'
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
276 'enddef'], 'E1095:')
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
277 enddef
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20903
diff changeset
278
22620
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
279 def Test_return_bool()
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
280 var lines =<< trim END
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
281 vim9script
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
282 def MenuFilter(id: number, key: string): bool
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
283 return popup_filter_menu(id, key)
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
284 enddef
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
285 def YesnoFilter(id: number, key: string): bool
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
286 return popup_filter_yesno(id, key)
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
287 enddef
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
288 defcompile
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
289 END
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
290 CheckScriptSuccess(lines)
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
291 enddef
b5d68d8a5187 patch 8.2.1858: Vim9: filter functions return number instead of bool
Bram Moolenaar <Bram@vim.org>
parents: 22586
diff changeset
292
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 let s:nothing = 0
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 def ReturnNothing()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 s:nothing = 1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 if true
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 return
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 endif
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 s:nothing = 2
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
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 def Test_return_nothing()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 ReturnNothing()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
304 s:nothing->assert_equal(1)
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306
23630
ca98d85e92da patch 8.2.2357: Vim9: crash when parsing function return type fails
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
307 def Test_return_invalid()
ca98d85e92da patch 8.2.2357: Vim9: crash when parsing function return type fails
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
308 var lines =<< trim END
ca98d85e92da patch 8.2.2357: Vim9: crash when parsing function return type fails
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
309 vim9script
ca98d85e92da patch 8.2.2357: Vim9: crash when parsing function return type fails
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
310 def Func(): invalid
ca98d85e92da patch 8.2.2357: Vim9: crash when parsing function return type fails
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
311 return xxx
ca98d85e92da patch 8.2.2357: Vim9: crash when parsing function return type fails
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
312 enddef
ca98d85e92da patch 8.2.2357: Vim9: crash when parsing function return type fails
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
313 defcompile
ca98d85e92da patch 8.2.2357: Vim9: crash when parsing function return type fails
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
314 END
ca98d85e92da patch 8.2.2357: Vim9: crash when parsing function return type fails
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
315 CheckScriptFailure(lines, 'E1010:', 2)
23925
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
316
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
317 lines =<< trim END
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
318 vim9script
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
319 def Test(Fun: func(number): number): list<number>
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
320 return map([1, 2, 3], (_, i) => Fun(i))
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
321 enddef
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
322 defcompile
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
323 def Inc(nr: number): nr
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
324 return nr + 2
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
325 enddef
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
326 echo Test(Inc)
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
327 END
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
328 # doing this twice was leaking memory
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
329 CheckScriptFailure(lines, 'E1010:')
e979bf909fd8 patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
330 CheckScriptFailure(lines, 'E1010:')
23630
ca98d85e92da patch 8.2.2357: Vim9: crash when parsing function return type fails
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
331 enddef
ca98d85e92da patch 8.2.2357: Vim9: crash when parsing function return type fails
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
332
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 func Increment()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 let g:counter += 1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 def Test_call_ufunc_count()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 g:counter = 1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 Increment()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 Increment()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 Increment()
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21347
diff changeset
342 # works with and without :call
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
343 g:counter->assert_equal(4)
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
344 eval g:counter->assert_equal(4)
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 unlet g:counter
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 def MyVarargs(arg: string, ...rest: list<string>): string
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
349 var res = arg
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 for s in rest
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 res ..= ',' .. s
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 endfor
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 return res
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 def Test_call_varargs()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
357 MyVarargs('one')->assert_equal('one')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
358 MyVarargs('one', 'two')->assert_equal('one,two')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
359 MyVarargs('one', 'two', 'three')->assert_equal('one,two,three')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 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
363 return name
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365
21345
5dd4cbc1e9e6 patch 8.2.1223: Vim9: invalid type error for function default value
Bram Moolenaar <Bram@vim.org>
parents: 21335
diff changeset
366 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
367 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
368 enddef
5dd4cbc1e9e6 patch 8.2.1223: Vim9: invalid type error for function default value
Bram Moolenaar <Bram@vim.org>
parents: 21335
diff changeset
369
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
370
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 def Test_call_default_args()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
372 MyDefaultArgs()->assert_equal('string')
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
373 MyDefaultArgs(v:none)->assert_equal('string')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
374 MyDefaultArgs('one')->assert_equal('one')
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
375 assert_fails('MyDefaultArgs("one", "two")', 'E118:', '', 4, 'Test_call_default_args')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
377 MyDefaultSecond('test')->assert_equal('test')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
378 MyDefaultSecond('test', true)->assert_equal('test')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
379 MyDefaultSecond('test', false)->assert_equal('none')
21345
5dd4cbc1e9e6 patch 8.2.1223: Vim9: invalid type error for function default value
Bram Moolenaar <Bram@vim.org>
parents: 21335
diff changeset
380
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
381 var lines =<< trim END
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
382 def MyDefaultThird(name: string, aa = 'aa', bb = 'bb'): string
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
383 return name .. aa .. bb
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
384 enddef
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
385
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
386 MyDefaultThird('->')->assert_equal('->aabb')
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
387 MyDefaultThird('->', v:none)->assert_equal('->aabb')
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
388 MyDefaultThird('->', 'xx')->assert_equal('->xxbb')
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
389 MyDefaultThird('->', v:none, v:none)->assert_equal('->aabb')
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
390 MyDefaultThird('->', 'xx', v:none)->assert_equal('->xxbb')
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
391 MyDefaultThird('->', v:none, 'yy')->assert_equal('->aayy')
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
392 MyDefaultThird('->', 'xx', 'yy')->assert_equal('->xxyy')
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
393 END
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
394 CheckDefAndScriptSuccess(lines)
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
395
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
396 CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
397 delfunc g:Func
22296
006b8ab9d554 patch 8.2.1697: inconsistent capitalization of error messages
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
398 CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: Argument 1: type mismatch, expected number but got string')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
399 delfunc g:Func
24695
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
400 CheckDefFailure(['def Func(x: number = )', 'enddef'], 'E15:')
24097
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24069
diff changeset
401
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
402 lines =<< trim END
24097
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24069
diff changeset
403 vim9script
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24069
diff changeset
404 def Func(a = b == 0 ? 1 : 2, b = 0)
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24069
diff changeset
405 enddef
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24069
diff changeset
406 defcompile
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24069
diff changeset
407 END
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24069
diff changeset
408 CheckScriptFailure(lines, 'E1001: Variable not found: b')
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
409 enddef
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
410
23511
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
411 def FuncWithComment( # comment
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
412 a: number, #comment
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
413 b: bool, # comment
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
414 c: string) #comment
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
415 assert_equal(4, a)
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
416 assert_equal(true, b)
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
417 assert_equal('yes', c)
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
418 enddef
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
419
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
420 def Test_func_with_comments()
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
421 FuncWithComment(4, true, 'yes')
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
422
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
423 var lines =<< trim END
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
424 def Func(# comment
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
425 arg: string)
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
426 enddef
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
427 END
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
428 CheckScriptFailure(lines, 'E125:', 1)
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
429
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
430 lines =<< trim END
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
431 def Func(
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
432 arg: string# comment
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
433 )
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
434 enddef
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
435 END
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
436 CheckScriptFailure(lines, 'E475:', 2)
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
437
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
438 lines =<< trim END
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
439 def Func(
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
440 arg: string
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
441 )# comment
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
442 enddef
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
443 END
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
444 CheckScriptFailure(lines, 'E488:', 3)
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
445 enddef
7e8703464f01 patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
446
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
447 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
448 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
449 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
450 enddef
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
451 Nested('function')->assert_equal('nested function')
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
452
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
453 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
454 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
455
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
456 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
457 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
458 CheckDefFailure(['def b:Nested()', 'enddef'], 'E1075:')
22216
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22214
diff changeset
459
23112
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
460 var lines =<< trim END
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
461 def Outer()
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
462 def Inner()
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
463 # comment
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
464 enddef
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
465 def Inner()
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
466 enddef
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
467 enddef
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
468 END
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
469 CheckDefFailure(lines, 'E1073:')
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
470
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
471 lines =<< trim END
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
472 def Outer()
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
473 def Inner()
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
474 # comment
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
475 enddef
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
476 def! Inner()
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
477 enddef
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
478 enddef
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
479 END
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
480 CheckDefFailure(lines, 'E1117:')
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
481
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
482 # nested function inside conditional
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
483 lines =<< trim END
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
484 vim9script
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
485 var thecount = 0
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
486 if true
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
487 def Test(): number
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
488 def TheFunc(): number
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
489 thecount += 1
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
490 return thecount
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
491 enddef
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
492 return TheFunc()
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
493 enddef
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
494 endif
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
495 defcompile
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
496 assert_equal(1, Test())
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
497 assert_equal(2, Test())
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
498 END
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
499 CheckScriptSuccess(lines)
24152
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
500
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
501 # also works when "thecount" is inside the "if" block
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
502 lines =<< trim END
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
503 vim9script
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
504 if true
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
505 var thecount = 0
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
506 def Test(): number
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
507 def TheFunc(): number
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
508 thecount += 1
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
509 return thecount
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
510 enddef
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
511 return TheFunc()
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
512 enddef
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
513 endif
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
514 defcompile
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
515 assert_equal(1, Test())
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
516 assert_equal(2, Test())
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
517 END
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
518 CheckScriptSuccess(lines)
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520
23426
c3c690c8fcbf patch 8.2.2256: Vim9: cannot use function( after line break in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
521 def Test_not_nested_function()
c3c690c8fcbf patch 8.2.2256: Vim9: cannot use function( after line break in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
522 echo printf('%d',
c3c690c8fcbf patch 8.2.2256: Vim9: cannot use function( after line break in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
523 function('len')('xxx'))
c3c690c8fcbf patch 8.2.2256: Vim9: cannot use function( after line break in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
524 enddef
c3c690c8fcbf patch 8.2.2256: Vim9: cannot use function( after line break in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
525
21566
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
526 func Test_call_default_args_from_func()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
527 call MyDefaultArgs()->assert_equal('string')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
528 call MyDefaultArgs('one')->assert_equal('one')
22163
b6d36f0b4f03 patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents: 22159
diff changeset
529 call assert_fails('call MyDefaultArgs("one", "two")', 'E118:', '', 3, 'Test_call_default_args_from_func')
21566
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
530 endfunc
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
531
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
532 def Test_nested_global_function()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
533 var lines =<< trim END
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
534 vim9script
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
535 def Outer()
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
536 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
537 return 'inner'
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
538 enddef
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
539 enddef
21566
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
540 defcompile
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
541 Outer()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
542 g:Inner()->assert_equal('inner')
21566
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
543 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
544 Outer()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
545 g:Inner()->assert_equal('inner')
21566
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
546 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
547 Outer()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
548 g:Inner()->assert_equal('inner')
21566
1e3e5058041c patch 8.2.1333: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
549 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
550 END
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
551 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
552
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
553 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
554 vim9script
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
555 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
556 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
557 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
558 enddef
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
559 enddef
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
560 defcompile
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
561 Outer()
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
562 Outer()
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
563 END
9ade1da22402 patch 8.2.1344: Vim9: No test for trying to redefine global function
Bram Moolenaar <Bram@vim.org>
parents: 21586
diff changeset
564 CheckScriptFailure(lines, "E122:")
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
565 delfunc g:Inner
21604
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
566
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
567 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
568 vim9script
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
569 def Outer()
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
570 def g:Inner()
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
571 echo map([1, 2, 3], (_, v) => v + 1)
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
572 enddef
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
573 g:Inner()
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
574 enddef
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
575 Outer()
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
576 END
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
577 CheckScriptSuccess(lines)
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
578 delfunc g:Inner
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
579
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
580 lines =<< trim END
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
581 vim9script
21604
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
582 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
583 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
584 enddef
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
585 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
586 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
587 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
588 enddef
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
589 enddef
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
590 defcompile
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
591 END
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
592 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
593 enddef
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21544
diff changeset
594
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
595 def DefListAll()
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
596 def
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
597 enddef
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
598
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
599 def DefListOne()
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
600 def DefListOne
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
601 enddef
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
602
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
603 def DefListMatches()
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
604 def /DefList
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
605 enddef
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
606
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
607 def Test_nested_def_list()
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
608 var funcs = split(execute('call DefListAll()'), "\n")
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
609 assert_true(len(funcs) > 10)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
610 assert_true(funcs->index('def DefListAll()') >= 0)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
611
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
612 funcs = split(execute('call DefListOne()'), "\n")
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
613 assert_equal([' def DefListOne()', '1 def DefListOne', ' enddef'], funcs)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
614
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
615 funcs = split(execute('call DefListMatches()'), "\n")
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
616 assert_true(len(funcs) >= 3)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
617 assert_true(funcs->index('def DefListAll()') >= 0)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
618 assert_true(funcs->index('def DefListOne()') >= 0)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
619 assert_true(funcs->index('def DefListMatches()') >= 0)
23112
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
620
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
621 var lines =<< trim END
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
622 vim9script
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
623 def Func()
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
624 def +Func+
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
625 enddef
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
626 defcompile
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
627 END
892303d45d2a patch 8.2.2102: Vim9: not all error messages tested
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
628 CheckScriptFailure(lines, 'E476:', 1)
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
629 enddef
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22969
diff changeset
630
21586
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
631 def Test_global_local_function()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
632 var lines =<< trim END
21586
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
633 vim9script
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
634 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
635 return 'global'
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
636 enddef
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
637 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
638 return 'local'
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
639 enddef
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
640 g:Func()->assert_equal('global')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
641 Func()->assert_equal('local')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
642 delfunc g:Func
21586
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
643 END
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
644 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
645
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
646 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
647 vim9script
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
648 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
649 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
650 enddef
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
651 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
652 END
7e1316c6d0eb patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
653 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
654 enddef
5470c36ed7e6 patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents: 21566
diff changeset
655
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
656 def Test_local_function_shadows_global()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
657 var lines =<< trim END
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
658 vim9script
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
659 def g:Gfunc(): string
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
660 return 'global'
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
661 enddef
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
662 def AnotherFunc(): number
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
663 var Gfunc = function('len')
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
664 return Gfunc('testing')
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
665 enddef
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
666 g:Gfunc()->assert_equal('global')
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
667 AnotherFunc()->assert_equal(7)
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
668 delfunc g:Gfunc
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
669 END
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
670 CheckScriptSuccess(lines)
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
671
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
672 lines =<< trim END
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
673 vim9script
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
674 def g:Func(): string
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
675 return 'global'
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
676 enddef
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
677 def AnotherFunc()
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
678 g:Func = function('len')
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
679 enddef
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
680 AnotherFunc()
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
681 END
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
682 CheckScriptFailure(lines, 'E705:')
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
683 delfunc g:Func
24355
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
684
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
685 # global function is found without g: prefix
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
686 lines =<< trim END
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
687 vim9script
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
688 def g:Func(): string
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
689 return 'global'
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
690 enddef
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
691 def AnotherFunc(): string
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
692 return Func()
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
693 enddef
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
694 assert_equal('global', AnotherFunc())
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
695 delfunc g:Func
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
696 END
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
697 CheckScriptSuccess(lines)
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
698
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
699 lines =<< trim END
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
700 vim9script
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
701 def g:Func(): string
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
702 return 'global'
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
703 enddef
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
704 assert_equal('global', Func())
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
705 delfunc g:Func
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
706 END
beb395ca3e2f patch 8.2.2718: Vim9: no explicit test for using a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
707 CheckScriptSuccess(lines)
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
708 enddef
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22222
diff changeset
709
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 func TakesOneArg(arg)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 echo a:arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 def Test_call_wrong_args()
22147
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 22139
diff changeset
715 CheckDefFailure(['TakesOneArg()'], 'E119:')
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 22139
diff changeset
716 CheckDefFailure(['TakesOneArg(11, 22)'], 'E118:')
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 22139
diff changeset
717 CheckDefFailure(['bufnr(xxx)'], 'E1001:')
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 22139
diff changeset
718 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
719
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
720 var lines =<< trim END
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
721 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
722 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
723 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
724 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
725 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
726 END
22296
006b8ab9d554 patch 8.2.1697: inconsistent capitalization of error messages
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
727 CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 5)
22318
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
728
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
729 lines =<< trim END
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
730 vim9script
23996
c192411b27e8 patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents: 23940
diff changeset
731 var name = 'piet'
c192411b27e8 patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents: 23940
diff changeset
732 def FuncOne(name: string)
c192411b27e8 patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents: 23940
diff changeset
733 echo nr
c192411b27e8 patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents: 23940
diff changeset
734 enddef
c192411b27e8 patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents: 23940
diff changeset
735 END
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
736 CheckScriptFailure(lines, 'E1168:')
23996
c192411b27e8 patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents: 23940
diff changeset
737
c192411b27e8 patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents: 23940
diff changeset
738 lines =<< trim END
c192411b27e8 patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents: 23940
diff changeset
739 vim9script
22318
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
740 def FuncOne(nr: number)
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
741 echo nr
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
742 enddef
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
743 def FuncTwo()
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
744 FuncOne()
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
745 enddef
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
746 defcompile
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
747 END
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
748 writefile(lines, 'Xscript')
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
749 var didCatch = false
22318
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
750 try
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
751 source Xscript
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
752 catch
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
753 assert_match('E119: Not enough arguments for function: <SNR>\d\+_FuncOne', v:exception)
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
754 assert_match('Xscript\[8\]..function <SNR>\d\+_FuncTwo, line 1', v:throwpoint)
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
755 didCatch = true
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
756 endtry
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
757 assert_true(didCatch)
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
758
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
759 lines =<< trim END
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
760 vim9script
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
761 def FuncOne(nr: number)
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
762 echo nr
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
763 enddef
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
764 def FuncTwo()
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
765 FuncOne(1, 2)
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
766 enddef
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
767 defcompile
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
768 END
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
769 writefile(lines, 'Xscript')
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
770 didCatch = false
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
771 try
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
772 source Xscript
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
773 catch
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
774 assert_match('E118: Too many arguments for function: <SNR>\d\+_FuncOne', v:exception)
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
775 assert_match('Xscript\[8\]..function <SNR>\d\+_FuncTwo, line 1', v:throwpoint)
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
776 didCatch = true
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
777 endtry
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
778 assert_true(didCatch)
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
779
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22314
diff changeset
780 delete('Xscript')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782
23252
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
783 def Test_call_funcref_wrong_args()
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
784 var head =<< trim END
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
785 vim9script
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
786 def Func3(a1: string, a2: number, a3: list<number>)
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
787 echo a1 .. a2 .. a3[0]
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
788 enddef
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
789 def Testme()
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
790 var funcMap: dict<func> = {func: Func3}
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
791 END
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
792 var tail =<< trim END
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
793 enddef
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
794 Testme()
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
795 END
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
796 CheckScriptSuccess(head + ["funcMap['func']('str', 123, [1, 2, 3])"] + tail)
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
797
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
798 CheckScriptFailure(head + ["funcMap['func']('str', 123)"] + tail, 'E119:')
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
799 CheckScriptFailure(head + ["funcMap['func']('str', 123, [1], 4)"] + tail, 'E118:')
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
800
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
801 var lines =<< trim END
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
802 vim9script
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
803 var Ref: func(number): any
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
804 Ref = (j) => !j
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
805 echo Ref(false)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
806 END
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
807 CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got bool', 4)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
808
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
809 lines =<< trim END
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
810 vim9script
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
811 var Ref: func(number): any
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
812 Ref = (j) => !j
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
813 call Ref(false)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
814 END
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23511
diff changeset
815 CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got bool', 4)
23252
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
816 enddef
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
817
22816
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
818 def Test_call_lambda_args()
24400
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
819 var lines =<< trim END
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
820 var Callback = (..._) => 'anything'
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
821 assert_equal('anything', Callback())
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
822 assert_equal('anything', Callback(1))
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
823 assert_equal('anything', Callback('a', 2))
24402
009a540f16a6 patch 8.2.2741: Vim9: Partial call does not check right arguments
Bram Moolenaar <Bram@vim.org>
parents: 24400
diff changeset
824
009a540f16a6 patch 8.2.2741: Vim9: Partial call does not check right arguments
Bram Moolenaar <Bram@vim.org>
parents: 24400
diff changeset
825 assert_equal('xyz', ((a: string): string => a)('xyz'))
24400
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
826 END
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
827 CheckDefAndScriptSuccess(lines)
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
828
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
829 CheckDefFailure(['echo ((i) => 0)()'],
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
830 'E119: Not enough arguments for function: ((i) => 0)()')
22816
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
831
24400
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
832 lines =<< trim END
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
833 var Ref = (x: number, y: number) => x + y
22816
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
834 echo Ref(1, 'x')
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
835 END
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
836 CheckDefFailure(lines, 'E1013: Argument 2: type mismatch, expected number but got string')
23481
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23444
diff changeset
837
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23444
diff changeset
838 lines =<< trim END
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23444
diff changeset
839 var Ref: func(job, string, number)
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23444
diff changeset
840 Ref = (x, y) => 0
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23444
diff changeset
841 END
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23444
diff changeset
842 CheckDefAndScriptFailure(lines, 'E1012:')
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23444
diff changeset
843
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23444
diff changeset
844 lines =<< trim END
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23444
diff changeset
845 var Ref: func(job, string)
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23444
diff changeset
846 Ref = (x, y, z) => 0
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23444
diff changeset
847 END
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23444
diff changeset
848 CheckDefAndScriptFailure(lines, 'E1012:')
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
849
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
850 lines =<< trim END
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
851 var one = 1
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
852 var l = [1, 2, 3]
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
853 echo map(l, (one) => one)
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
854 END
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
855 CheckDefFailure(lines, 'E1167:')
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
856 CheckScriptFailure(['vim9script'] + lines, 'E1168:')
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
857
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
858 lines =<< trim END
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
859 def ShadowLocal()
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
860 var one = 1
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
861 var l = [1, 2, 3]
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
862 echo map(l, (one) => one)
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
863 enddef
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
864 END
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
865 CheckDefFailure(lines, 'E1167:')
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
866
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
867 lines =<< trim END
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
868 def Shadowarg(one: number)
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
869 var l = [1, 2, 3]
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
870 echo map(l, (one) => one)
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
871 enddef
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
872 END
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
873 CheckDefFailure(lines, 'E1167:')
24398
bed5ec739304 patch 8.2.2739: Vim9: a lambda accepts too many arguments at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24371
diff changeset
874
bed5ec739304 patch 8.2.2739: Vim9: a lambda accepts too many arguments at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24371
diff changeset
875 lines =<< trim END
bed5ec739304 patch 8.2.2739: Vim9: a lambda accepts too many arguments at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24371
diff changeset
876 echo ((a) => a)('aa', 'bb')
bed5ec739304 patch 8.2.2739: Vim9: a lambda accepts too many arguments at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24371
diff changeset
877 END
bed5ec739304 patch 8.2.2739: Vim9: a lambda accepts too many arguments at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24371
diff changeset
878 CheckDefAndScriptFailure(lines, 'E118:', 1)
22816
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
879 enddef
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
880
24156
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
881 def FilterWithCond(x: string, Cond: func(string): bool): bool
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
882 return Cond(x)
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
883 enddef
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
884
23808
baf9069f64ca patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents: 23727
diff changeset
885 def Test_lambda_return_type()
baf9069f64ca patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents: 23727
diff changeset
886 var lines =<< trim END
baf9069f64ca patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents: 23727
diff changeset
887 var Ref = (): => 123
baf9069f64ca patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents: 23727
diff changeset
888 END
baf9069f64ca patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents: 23727
diff changeset
889 CheckDefAndScriptFailure(lines, 'E1157:', 1)
24156
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
890
24685
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24651
diff changeset
891 # no space before the return type
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24651
diff changeset
892 lines =<< trim END
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24651
diff changeset
893 var Ref = (x):number => x + 1
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24651
diff changeset
894 END
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24651
diff changeset
895 CheckDefAndScriptFailure(lines, 'E1069:', 1)
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24651
diff changeset
896
24156
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
897 # this works
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
898 for x in ['foo', 'boo']
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
899 echo FilterWithCond(x, (v) => v =~ '^b')
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
900 endfor
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
901
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
902 # this fails
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
903 lines =<< trim END
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
904 echo FilterWithCond('foo', (v) => v .. '^b')
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
905 END
a358fa462560 patch 8.2.2619: Vim9: no test for return type of lambda
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
906 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected func(string): bool but got func(any): string', 1)
23808
baf9069f64ca patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents: 23727
diff changeset
907 enddef
baf9069f64ca patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents: 23727
diff changeset
908
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23112
diff changeset
909 def Test_lambda_uses_assigned_var()
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23112
diff changeset
910 CheckDefSuccess([
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23112
diff changeset
911 'var x: any = "aaa"'
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
912 'x = filter(["bbb"], (_, v) => v =~ x)'])
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23112
diff changeset
913 enddef
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23112
diff changeset
914
24061
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
915 def Test_pass_legacy_lambda_to_def_func()
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
916 var lines =<< trim END
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
917 vim9script
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
918 func Foo()
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
919 eval s:Bar({x -> 0})
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
920 endfunc
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
921 def Bar(y: any)
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
922 enddef
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
923 Foo()
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
924 END
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
925 CheckScriptSuccess(lines)
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
926 enddef
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
927
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 " Default arg and varargs
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 def MyDefVarargs(one: string, two = 'foo', ...rest: list<string>): string
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
930 var res = one .. ',' .. two
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 for s in rest
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 res ..= ',' .. s
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 endfor
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 return res
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 def Test_call_def_varargs()
22163
b6d36f0b4f03 patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents: 22159
diff changeset
938 assert_fails('MyDefVarargs()', 'E119:', '', 1, 'Test_call_def_varargs')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
939 MyDefVarargs('one')->assert_equal('one,foo')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
940 MyDefVarargs('one', 'two')->assert_equal('one,two')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
941 MyDefVarargs('one', 'two', 'three')->assert_equal('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
942 CheckDefFailure(['MyDefVarargs("one", 22)'],
22296
006b8ab9d554 patch 8.2.1697: inconsistent capitalization of error messages
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
943 'E1013: Argument 2: type mismatch, expected string but got number')
21481
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
944 CheckDefFailure(['MyDefVarargs("one", "two", 123)'],
22296
006b8ab9d554 patch 8.2.1697: inconsistent capitalization of error messages
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
945 'E1013: Argument 3: type mismatch, expected string but got number')
21481
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
946
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
947 var lines =<< trim END
21481
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
948 vim9script
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
949 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
950 echo l
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
951 enddef
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
952 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
953 END
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
954 CheckScriptSuccess(lines)
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
955
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
956 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
957 vim9script
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
958 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
959 echo l
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
960 enddef
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
961 Func()
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
962 END
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
963 CheckScriptSuccess(lines)
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
964
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
965 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
966 vim9script
24400
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
967 def Func(...l: list<any>)
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
968 echo l
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
969 enddef
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
970 Func(0)
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
971 END
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
972 CheckScriptSuccess(lines)
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
973
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
974 lines =<< trim END
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
975 vim9script
22292
3515f341e8ac patch 8.2.1695: Vim9: crash when using varargs type "any"
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
976 def Func(...l: any)
3515f341e8ac patch 8.2.1695: Vim9: crash when using varargs type "any"
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
977 echo l
3515f341e8ac patch 8.2.1695: Vim9: crash when using varargs type "any"
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
978 enddef
3515f341e8ac patch 8.2.1695: Vim9: crash when using varargs type "any"
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
979 Func(0)
3515f341e8ac patch 8.2.1695: Vim9: crash when using varargs type "any"
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
980 END
24400
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24398
diff changeset
981 CheckScriptFailure(lines, 'E1180:', 2)
22292
3515f341e8ac patch 8.2.1695: Vim9: crash when using varargs type "any"
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
982
3515f341e8ac patch 8.2.1695: Vim9: crash when using varargs type "any"
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
983 lines =<< trim END
3515f341e8ac patch 8.2.1695: Vim9: crash when using varargs type "any"
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
984 vim9script
22349
b66a2e046c2e patch 8.2.1723: Vim9: Variable argument name cannot start with underscore
Bram Moolenaar <Bram@vim.org>
parents: 22339
diff changeset
985 def Func(..._l: list<string>)
b66a2e046c2e patch 8.2.1723: Vim9: Variable argument name cannot start with underscore
Bram Moolenaar <Bram@vim.org>
parents: 22339
diff changeset
986 echo _l
b66a2e046c2e patch 8.2.1723: Vim9: Variable argument name cannot start with underscore
Bram Moolenaar <Bram@vim.org>
parents: 22339
diff changeset
987 enddef
b66a2e046c2e patch 8.2.1723: Vim9: Variable argument name cannot start with underscore
Bram Moolenaar <Bram@vim.org>
parents: 22339
diff changeset
988 Func('a', 'b', 'c')
b66a2e046c2e patch 8.2.1723: Vim9: Variable argument name cannot start with underscore
Bram Moolenaar <Bram@vim.org>
parents: 22339
diff changeset
989 END
b66a2e046c2e patch 8.2.1723: Vim9: Variable argument name cannot start with underscore
Bram Moolenaar <Bram@vim.org>
parents: 22339
diff changeset
990 CheckScriptSuccess(lines)
b66a2e046c2e patch 8.2.1723: Vim9: Variable argument name cannot start with underscore
Bram Moolenaar <Bram@vim.org>
parents: 22339
diff changeset
991
b66a2e046c2e patch 8.2.1723: Vim9: Variable argument name cannot start with underscore
Bram Moolenaar <Bram@vim.org>
parents: 22339
diff changeset
992 lines =<< trim END
b66a2e046c2e patch 8.2.1723: Vim9: Variable argument name cannot start with underscore
Bram Moolenaar <Bram@vim.org>
parents: 22339
diff changeset
993 vim9script
21481
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
994 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
995 echo l
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
996 enddef
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
997 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
998 END
22296
006b8ab9d554 patch 8.2.1697: inconsistent capitalization of error messages
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
999 CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch')
21481
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
1000
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
1001 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
1002 vim9script
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
1003 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
1004 echo l
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
1005 enddef
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
1006 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
1007 END
22296
006b8ab9d554 patch 8.2.1697: inconsistent capitalization of error messages
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1008 CheckScriptFailure(lines, 'E1013: Argument 2: type mismatch')
21481
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
1009
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
1010 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
1011 vim9script
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
1012 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
1013 echo l
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
1014 enddef
279b3415947f patch 8.2.1291: Vim9: type of varargs items is not checked
Bram Moolenaar <Bram@vim.org>
parents: 21475
diff changeset
1015 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
1016 END
22296
006b8ab9d554 patch 8.2.1697: inconsistent capitalization of error messages
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1017 CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch')
23879
9ddf1a537fc2 patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents: 23808
diff changeset
1018
9ddf1a537fc2 patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents: 23808
diff changeset
1019 lines =<< trim END
9ddf1a537fc2 patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents: 23808
diff changeset
1020 vim9script
9ddf1a537fc2 patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents: 23808
diff changeset
1021 def Func( # some comment
9ddf1a537fc2 patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents: 23808
diff changeset
1022 ...l = []
9ddf1a537fc2 patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents: 23808
diff changeset
1023 )
9ddf1a537fc2 patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents: 23808
diff changeset
1024 echo l
9ddf1a537fc2 patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents: 23808
diff changeset
1025 enddef
9ddf1a537fc2 patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents: 23808
diff changeset
1026 END
9ddf1a537fc2 patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents: 23808
diff changeset
1027 CheckScriptFailure(lines, 'E1160:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1030 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
1031
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1032 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
1033 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
1034 enddef
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1035
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1036 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
1037 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
1038 enddef
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1039
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1040 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
1041 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
1042 enddef
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1043
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1044 def Test_func_type_varargs()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1045 var RefDefArg: func(?string)
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1046 RefDefArg = FuncOneDefArg
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1047 RefDefArg()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1048 s:value->assert_equal('text')
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1049 RefDefArg('some')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1050 s:value->assert_equal('some')
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1051
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1052 var RefDef2Arg: func(?number, ?string): string
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1053 RefDef2Arg = FuncTwoDefArg
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1054 RefDef2Arg()->assert_equal('123text')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1055 RefDef2Arg(99)->assert_equal('99text')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1056 RefDef2Arg(77, 'some')->assert_equal('77some')
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1057
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1058 CheckDefFailure(['var RefWrong: func(string?)'], 'E1010:')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1059 CheckDefFailure(['var RefWrong: func(?string, string)'], 'E1007:')
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1060
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1061 var RefVarargs: func(...list<string>): string
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1062 RefVarargs = FuncVarargs
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1063 RefVarargs()->assert_equal('')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1064 RefVarargs('one')->assert_equal('one')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1065 RefVarargs('one', 'two')->assert_equal('one,two')
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1066
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1067 CheckDefFailure(['var RefWrong: func(...list<string>, string)'], 'E110:')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1068 CheckDefFailure(['var RefWrong: func(...list<string>, ?string)'], 'E110:')
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1069 enddef
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1070
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1071 " Only varargs
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1072 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
1073 return join(args, ',')
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1074 enddef
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1075
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1076 def Test_call_varargs_only()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1077 MyVarargsOnly()->assert_equal('')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1078 MyVarargsOnly('one')->assert_equal('one')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1079 MyVarargsOnly('one', 'two')->assert_equal('one,two')
22296
006b8ab9d554 patch 8.2.1697: inconsistent capitalization of error messages
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1080 CheckDefFailure(['MyVarargsOnly(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
006b8ab9d554 patch 8.2.1697: inconsistent capitalization of error messages
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1081 CheckDefFailure(['MyVarargsOnly("one", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number')
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1082 enddef
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1083
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 def Test_using_var_as_arg()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1085 writefile(['def Func(x: number)', 'var x = 234', 'enddef', 'defcompile'], 'Xdef')
22163
b6d36f0b4f03 patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents: 22159
diff changeset
1086 assert_fails('so Xdef', 'E1006:', '', 1, 'Func')
22147
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 22139
diff changeset
1087 delete('Xdef')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089
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
1090 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
1091 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
1092 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
1093
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
1094 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
1095 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
1096 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
1097
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20303
diff changeset
1098 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
1099 # works for dict and list
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1100 var d: dict<string> = {}
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
1101 DictArg(d)
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1102 d['key']->assert_equal('value')
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1103 var l: list<string> = []
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
1104 ListArg(l)
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1105 l[0]->assert_equal('value')
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
1106
22147
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 22139
diff changeset
1107 CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef', 'defcompile'], 'E1090:')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
1108 delfunc! g:Func
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
1109 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
1110
22339
56f674e7518c patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
1111 " These argument names are reserved in legacy functions.
56f674e7518c patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
1112 def WithReservedNames(firstline: string, lastline: string): string
56f674e7518c patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
1113 return firstline .. lastline
56f674e7518c patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
1114 enddef
56f674e7518c patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
1115
56f674e7518c patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
1116 def Test_argument_names()
56f674e7518c patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
1117 assert_equal('OK', WithReservedNames('O', 'K'))
56f674e7518c patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
1118 enddef
56f674e7518c patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
1119
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 def Test_call_func_defined_later()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1121 g:DefinedLater('one')->assert_equal('one')
22163
b6d36f0b4f03 patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents: 22159
diff changeset
1122 assert_fails('NotDefined("one")', 'E117:', '', 2, 'Test_call_func_defined_later')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
1125 func DefinedLater(arg)
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
1126 return a:arg
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
1127 endfunc
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
1128
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
1129 def Test_call_funcref()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1130 g:SomeFunc('abc')->assert_equal(3)
22163
b6d36f0b4f03 patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents: 22159
diff changeset
1131 assert_fails('NotAFunc()', 'E117:', '', 2, 'Test_call_funcref') # comment after call
b6d36f0b4f03 patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents: 22159
diff changeset
1132 assert_fails('g:NotAFunc()', 'E117:', '', 3, 'Test_call_funcref')
21439
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
1133
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1134 var lines =<< trim END
21439
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
1135 vim9script
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
1136 def RetNumber(): number
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
1137 return 123
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
1138 enddef
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1139 var Funcref: func: number = function('RetNumber')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1140 Funcref()->assert_equal(123)
21439
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
1141 END
166c15374bda patch 8.2.1270: Vim9: not skipping over function type declaration
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
1142 CheckScriptSuccess(lines)
21441
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
1143
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
1144 lines =<< trim END
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
1145 vim9script
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
1146 def RetNumber(): number
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
1147 return 123
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
1148 enddef
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
1149 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
1150 return F()
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
1151 enddef
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1152 var Funcref = function('RetNumber')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1153 Bar(Funcref)->assert_equal(123)
21441
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
1154 END
78d97ee2c707 patch 8.2.1271: Vim9: Error for Funcref function argument type
Bram Moolenaar <Bram@vim.org>
parents: 21439
diff changeset
1155 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
1156
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
1157 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
1158 vim9script
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
1159 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
1160 echo nr
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
1161 enddef
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1162 var Funcref: func(number) = function('UseNumber')
21467
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
1163 Funcref(123)
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
1164 END
49072a858baf patch 8.2.1284: Vim9: skipping over type includes following white space
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
1165 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
1166
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
1167 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
1168 vim9script
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
1169 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
1170 echo nr
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
1171 enddef
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1172 var Funcref: func(string) = function('UseNumber')
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
1173 END
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22264
diff changeset
1174 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
1175
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
1176 lines =<< trim END
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
1177 vim9script
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
1178 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
1179 g:echo = nr
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
1180 enddef
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1181 var Funcref: func(?number) = function('EchoNr')
21500
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
1182 Funcref()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1183 g:echo->assert_equal(34)
21500
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
1184 Funcref(123)
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1185 g:echo->assert_equal(123)
21500
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
1186 END
574517d682cf patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
1187 CheckScriptSuccess(lines)
21502
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
1188
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
1189 lines =<< trim END
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
1190 vim9script
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
1191 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
1192 g:echo = l
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
1193 enddef
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1194 var Funcref: func(...list<number>) = function('EchoList')
21502
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
1195 Funcref()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1196 g:echo->assert_equal([])
21502
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
1197 Funcref(1, 2, 3)
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1198 g:echo->assert_equal([1, 2, 3])
21502
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
1199 END
179697662a5a patch 8.2.1301: Vim9: varargs argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents: 21500
diff changeset
1200 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
1201
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
1202 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
1203 vim9script
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
1204 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
1205 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
1206 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
1207 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
1208 enddef
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1209 var Funcref: func(number, ?number, ...list<number>): number = function('OptAndVar')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1210 Funcref(10)->assert_equal(10)
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1211 g:optarg->assert_equal(12)
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1212 g:listarg->assert_equal([])
21504
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
1213
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1214 Funcref(11, 22)->assert_equal(11)
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1215 g:optarg->assert_equal(22)
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1216 g:listarg->assert_equal([])
21504
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
1217
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1218 Funcref(17, 18, 1, 2, 3)->assert_equal(17)
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1219 g:optarg->assert_equal(18)
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1220 g:listarg->assert_equal([1, 2, 3])
21504
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
1221 END
e87a97868bbc patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Bram Moolenaar <Bram@vim.org>
parents: 21502
diff changeset
1222 CheckScriptSuccess(lines)
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
1223 enddef
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
1224
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
1225 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
1226 let NotAFunc = 'text'
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
1227
19993
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
1228 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
1229 # same arguments, different return type
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1230 var Ref1: func(bool): string
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1231 var Ref2: func(bool): number
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1232 var Ref3: func(bool): any
19993
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
1233 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
1234
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21347
diff changeset
1235 # different number of arguments
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1236 var Refa1: func(bool): number
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1237 var Refa2: func(bool, number): number
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1238 var Refa3: func: number
19993
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
1239 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
1240
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21347
diff changeset
1241 # different argument types
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1242 var Refb1: func(bool, string): number
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1243 var Refb2: func(string, number): number
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1244 var Refb3: func(any, any): number
19993
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
1245 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
1246 enddef
efe864a7ce4f patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19985
diff changeset
1247
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 def FuncWithForwardCall()
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20029
diff changeset
1249 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
1250 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 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
1253 return arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 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
1257 # Error in called function requires unwinding the call stack.
22165
c512e6f57ff2 patch 8.2.1632: not checking the context of test_fails()
Bram Moolenaar <Bram@vim.org>
parents: 22163
diff changeset
1258 assert_fails('FuncWithForwardCall()', 'E1096:', '', 1, 'FuncWithForwardCall')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 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
1262 CheckScriptFailure([
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1263 '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
1264 'return "a"',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1265 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1266 'defcompile'], 'expected number but got string')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
1267 delfunc! g:Func
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1268 CheckScriptFailure([
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1269 '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
1270 'return 1',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1271 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1272 'defcompile'], 'expected string but got number')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
1273 delfunc! g:Func
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1274 CheckScriptFailure([
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1275 '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
1276 'return "a"',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1277 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1278 'defcompile'],
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1279 'E1096: Returning a value in a function without a return type')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
1280 delfunc! g:Func
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1281 CheckScriptFailure([
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1282 'def Func()',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1283 'return "a"',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1284 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1285 'defcompile'],
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1286 'E1096: Returning a value in a function without a return type')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
1287 delfunc! g:Func
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1289 CheckScriptFailure([
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1290 '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
1291 'return',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1292 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1293 'defcompile'], 'E1003:')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
1294 delfunc! g:Func
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
1297 delfunc! g:Func
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
1299 delfunc! g:Func
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1300 CheckScriptFailure(['def Func()', 'return 1'], 'E1057:')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
1301 delfunc! g:Func
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1302
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1303 CheckScriptFailure([
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1304 'vim9script',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1305 'def FuncB()',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1306 ' return 123',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1307 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1308 'def FuncA()',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1309 ' FuncB()',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1310 'enddef',
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
1311 'defcompile'], 'E1096:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 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
1315 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
1316 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
1317 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
1318 CheckScriptFailure(['def Func5(items)', 'echo "a"'], 'E1077:')
24695
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
1319 CheckScriptFailure(['def Func6(...x:list<number>)', 'echo "a"', 'enddef'], 'E1069:')
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
1320 CheckScriptFailure(['def Func7(...x: int)', 'echo "a"', 'enddef'], 'E1010:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322
24371
2b4883926a24 patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents: 24369
diff changeset
1323 def Test_white_space_before_comma()
2b4883926a24 patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents: 24369
diff changeset
1324 var lines =<< trim END
2b4883926a24 patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents: 24369
diff changeset
1325 vim9script
2b4883926a24 patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents: 24369
diff changeset
1326 def Func(a: number , b: number)
2b4883926a24 patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents: 24369
diff changeset
1327 enddef
2b4883926a24 patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents: 24369
diff changeset
1328 END
2b4883926a24 patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents: 24369
diff changeset
1329 CheckScriptFailure(lines, 'E1068:')
24685
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24651
diff changeset
1330 call assert_fails('vim9cmd echo stridx("a" .. "b" , "a")', 'E1068:')
24371
2b4883926a24 patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents: 24369
diff changeset
1331 enddef
2b4883926a24 patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents: 24369
diff changeset
1332
24069
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1333 def Test_white_space_after_comma()
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1334 var lines =<< trim END
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1335 vim9script
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1336 def Func(a: number,b: number)
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1337 enddef
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1338 END
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1339 CheckScriptFailure(lines, 'E1069:')
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1340
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1341 # OK in legacy function
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1342 lines =<< trim END
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1343 vim9script
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1344 func Func(a,b)
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1345 endfunc
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1346 END
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1347 CheckScriptSuccess(lines)
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1348 enddef
324408c61b20 patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
1349
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 def Test_vim9script_call()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1351 var lines =<< trim END
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 vim9script
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1353 var name = ''
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 def MyFunc(arg: string)
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1355 name = arg
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 MyFunc('foobar')
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1358 name->assert_equal('foobar')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1360 var str = 'barfoo'
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 str->MyFunc()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1362 name->assert_equal('barfoo')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363
20945
0653b9b72091 patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents: 20909
diff changeset
1364 g:value = 'value'
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 g:value->MyFunc()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1366 name->assert_equal('value')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1368 var listvar = []
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 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
1370 listvar = arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 [1, 2, 3]->ListFunc()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1373 listvar->assert_equal([1, 2, 3])
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1375 var dictvar = {}
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 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
1377 dictvar = arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 enddef
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
1379 {a: 1, b: 2}->DictFunc()
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
1380 dictvar->assert_equal({a: 1, b: 2})
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 def CompiledDict()
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
1382 {a: 3, b: 4}->DictFunc()
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 CompiledDict()
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
1385 dictvar->assert_equal({a: 3, b: 4})
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
1387 {a: 3, b: 4}->DictFunc()
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
1388 dictvar->assert_equal({a: 3, b: 4})
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 ('text')->MyFunc()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1391 name->assert_equal('text')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 ("some")->MyFunc()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1393 name->assert_equal('some')
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
1394
21475
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
1395 # 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
1396 # 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
1397 'asdfasdf'->MyFunc()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1398 name->assert_equal('asdfasdf')
21544
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
1399 "xyz"->MyFunc()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1400 name->assert_equal('xyz')
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
1401
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
1402 def UseString()
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
1403 'xyork'->MyFunc()
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
1404 enddef
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
1405 UseString()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1406 name->assert_equal('xyork')
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
1407
21544
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
1408 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
1409 "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
1410 enddef
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
1411 UseString2()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1412 name->assert_equal('knife')
21544
6c67c86a202a patch 8.2.1322: Vim9: method on double quoted string doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
1413
21475
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
1414 # 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
1415 new
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
1416 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
1417 normal! 3Gmt1G
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
1418 :'t
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1419 getcurpos()[1]->assert_equal(3)
21475
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
1420 bwipe!
eec2d2120cde patch 8.2.1288: Vim9: cannot use mark in range
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
1421
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
1422 MyFunc(
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
1423 'continued'
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
1424 )
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
1425 assert_equal('continued',
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1426 name
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
1427 )
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
1428
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
1429 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
1430 'more'
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
1431 ..
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
1432 'lines'
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
1433 )
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21089
diff changeset
1434 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
1435 'morelines',
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1436 name)
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 writefile(lines, 'Xcall.vim')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 source Xcall.vim
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 delete('Xcall.vim')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 def Test_vim9script_call_fail_decl()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1444 var lines =<< trim END
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 vim9script
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1446 var name = ''
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 def MyFunc(arg: string)
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1448 var name = 123
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 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
1450 defcompile
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 END
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21441
diff changeset
1452 CheckScriptFailure(lines, 'E1054:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454
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
1455 def Test_vim9script_call_fail_type()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1456 var lines =<< trim END
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
1457 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
1458 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
1459 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
1460 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
1461 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
1462 END
22296
006b8ab9d554 patch 8.2.1697: inconsistent capitalization of error messages
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1463 CheckScriptFailure(lines, 'E1013: Argument 1: 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
1464 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
1465
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 def Test_vim9script_call_fail_const()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1467 var lines =<< trim END
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 vim9script
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 const var = ''
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 def MyFunc(arg: string)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 var = 'asdf'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 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
1473 defcompile
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 writefile(lines, 'Xcall_const.vim')
22163
b6d36f0b4f03 patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents: 22159
diff changeset
1476 assert_fails('source Xcall_const.vim', 'E46:', '', 1, 'MyFunc')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 delete('Xcall_const.vim')
23295
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23291
diff changeset
1478
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23291
diff changeset
1479 lines =<< trim END
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23291
diff changeset
1480 const g:Aconst = 77
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23291
diff changeset
1481 def Change()
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23291
diff changeset
1482 # comment
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23291
diff changeset
1483 g:Aconst = 99
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23291
diff changeset
1484 enddef
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23291
diff changeset
1485 call Change()
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23291
diff changeset
1486 unlet g:Aconst
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23291
diff changeset
1487 END
23299
d5919c5fd3dc patch 8.2.2195: failing tests for :const
Bram Moolenaar <Bram@vim.org>
parents: 23297
diff changeset
1488 CheckScriptFailure(lines, 'E741: Value is locked: Aconst', 2)
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 " 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
1492 " recognized.
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 func Test_function_python()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 CheckFeature python3
22437
7bd80999ea21 patch 8.2.1767: Vim9: test fails with python support
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1495 let py = 'python3'
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 execute py "<< EOF"
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 def do_something():
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 return 1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 EOF
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 endfunc
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 def Test_delfunc()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1503 var lines =<< trim END
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 vim9script
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1505 def g:GoneSoon()
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 echo 'hello'
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 def CallGoneSoon()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 GoneSoon()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 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
1512 defcompile
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1514 delfunc g:GoneSoon
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 CallGoneSoon()
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 END
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 writefile(lines, 'XToDelFunc')
22163
b6d36f0b4f03 patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents: 22159
diff changeset
1518 assert_fails('so XToDelFunc', 'E933:', '', 1, 'CallGoneSoon')
b6d36f0b4f03 patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents: 22159
diff changeset
1519 assert_fails('so XToDelFunc', 'E933:', '', 1, 'CallGoneSoon')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 delete('XToDelFunc')
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 def Test_redef_failure()
22147
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 22139
diff changeset
1525 writefile(['def Func0(): string', 'return "Func0"', 'enddef'], 'Xdef')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 so Xdef
22147
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 22139
diff changeset
1527 writefile(['def Func1(): string', 'return "Func1"', 'enddef'], 'Xdef')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 so Xdef
22147
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 22139
diff changeset
1529 writefile(['def! Func0(): string', 'enddef', 'defcompile'], 'Xdef')
22163
b6d36f0b4f03 patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents: 22159
diff changeset
1530 assert_fails('so Xdef', 'E1027:', '', 1, 'Func0')
22147
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 22139
diff changeset
1531 writefile(['def Func2(): string', 'return "Func2"', 'enddef'], 'Xdef')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 so Xdef
22147
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 22139
diff changeset
1533 delete('Xdef')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1535 assert_fails('g:Func0()', 'E1091:')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1536 g:Func1()->assert_equal('Func1')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1537 g:Func2()->assert_equal('Func2')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 delfunc! Func0
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 delfunc! Func1
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 delfunc! Func2
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1544 def Test_vim9script_func()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1545 var lines =<< trim END
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1546 vim9script
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1547 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
1548 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
1549 endfunc
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1550 Func('text')
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1551 END
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1552 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
1553 so XVim9Func
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1554
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1555 delete('XVim9Func')
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1556 enddef
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1557
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 let s:funcResult = 0
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 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
1561 s:funcResult = 11
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 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
1565 s:funcResult = 22
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 return 1234
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1569 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
1570 s:funcResult = 45
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1571 return 'text'
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1572 enddef
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1573
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 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
1575 s:funcResult = arg
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 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
1579 s:funcResult = arg
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 return arg
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582
19985
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
1583 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
1584 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
1585 enddef
f863aa96cae5 patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
1586
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1587 def FuncOneArgRetString(arg: string): string
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1588 return arg
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1589 enddef
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1590
19926
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
1591 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
1592 return arg
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
1593 enddef
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
1594
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 def Test_func_type()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1596 var 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
1597 s:funcResult = 0
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 Ref1 = FuncNoArgNoRet
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 Ref1()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1600 s:funcResult->assert_equal(11)
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
1601
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1602 var 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
1603 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
1604 Ref2 = FuncNoArgNoRet
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
1605 Ref2()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1606 s:funcResult->assert_equal(11)
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
1607
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
1608 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
1609 Ref2 = FuncOneArgNoRet
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
1610 Ref2(12)
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1611 s:funcResult->assert_equal(12)
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
1612
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
1613 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
1614 Ref2 = FuncNoArgRetNumber
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1615 Ref2()->assert_equal(1234)
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1616 s:funcResult->assert_equal(22)
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
1617
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
1618 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
1619 Ref2 = FuncOneArgRetNumber
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1620 Ref2(13)->assert_equal(13)
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1621 s:funcResult->assert_equal(13)
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623
21162
3158cc2384cc patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21160
diff changeset
1624 def Test_repeat_return_type()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1625 var res = 0
21162
3158cc2384cc patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21160
diff changeset
1626 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
1627 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
1628 endfor
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1629 res->assert_equal(3)
21164
4a190861f0cc patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21162
diff changeset
1630
4a190861f0cc patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21162
diff changeset
1631 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
1632 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
1633 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
1634 endfor
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1635 res->assert_equal(6)
21162
3158cc2384cc patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21160
diff changeset
1636 enddef
3158cc2384cc patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents: 21160
diff changeset
1637
21170
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
1638 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
1639 next fileone filetwo
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1640 var res = ''
21170
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
1641 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
1642 res ..= name
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
1643 endfor
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1644 res->assert_equal('fileonefiletwo')
21170
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
1645 enddef
8c494353c6bc patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents: 21164
diff changeset
1646
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1647 def Test_func_type_part()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1648 var RefVoid: func: void
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1649 RefVoid = FuncNoArgNoRet
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1650 RefVoid = FuncOneArgNoRet
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1651 CheckDefFailure(['var RefVoid: func: void', 'RefVoid = FuncNoArgRetNumber'], 'E1012: Type mismatch; expected func(...) but got func(): number')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1652 CheckDefFailure(['var 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
1653
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1654 var RefAny: func(): any
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1655 RefAny = FuncNoArgRetNumber
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1656 RefAny = FuncNoArgRetString
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1657 CheckDefFailure(['var RefAny: func(): any', 'RefAny = FuncNoArgNoRet'], 'E1012: Type mismatch; expected func(): any but got func()')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1658 CheckDefFailure(['var 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
1659
22498
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1660 var RefAnyNoArgs: func: any = RefAny
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1661
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1662 var RefNr: func: number
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1663 RefNr = FuncNoArgRetNumber
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1664 RefNr = FuncOneArgRetNumber
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1665 CheckDefFailure(['var RefNr: func: number', 'RefNr = FuncNoArgNoRet'], 'E1012: Type mismatch; expected func(...): number but got func()')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1666 CheckDefFailure(['var 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
1667
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1668 var RefStr: func: string
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1669 RefStr = FuncNoArgRetString
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1670 RefStr = FuncOneArgRetString
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1671 CheckDefFailure(['var RefStr: func: string', 'RefStr = FuncNoArgNoRet'], 'E1012: Type mismatch; expected func(...): string but got func()')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1672 CheckDefFailure(['var 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
1673 enddef
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1674
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 def Test_func_type_fails()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1676 CheckDefFailure(['var ref1: func()'], 'E704:')
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1678 CheckDefFailure(['var Ref1: func()', 'Ref1 = FuncNoArgRetNumber'], 'E1012: Type mismatch; expected func() but got func(): number')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1679 CheckDefFailure(['var Ref1: func()', 'Ref1 = FuncOneArgNoRet'], 'E1012: Type mismatch; expected func() but got func(number)')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1680 CheckDefFailure(['var Ref1: func()', 'Ref1 = FuncOneArgRetNumber'], 'E1012: Type mismatch; expected func() but got func(number): number')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1681 CheckDefFailure(['var Ref1: func(bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1012: Type mismatch; expected func(bool) but got func(bool, number)')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1682 CheckDefFailure(['var Ref1: func(?bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1012: Type mismatch; expected func(?bool) but got func(bool, number)')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1683 CheckDefFailure(['var 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
1684
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1685 CheckDefFailure(['var RefWrong: func(string ,number)'], 'E1068:')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1686 CheckDefFailure(['var RefWrong: func(string,number)'], 'E1069:')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1687 CheckDefFailure(['var RefWrong: func(bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool)'], 'E1005:')
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1688 CheckDefFailure(['var 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
1689 enddef
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690
19926
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
1691 def Test_func_return_type()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1692 var nr: number
19926
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
1693 nr = FuncNoArgRetNumber()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1694 nr->assert_equal(1234)
19926
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
1695
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
1696 nr = FuncOneArgRetAny(122)
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1697 nr->assert_equal(122)
19926
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
1698
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1699 var str: string
19926
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
1700 str = FuncOneArgRetAny('yes')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1701 str->assert_equal('yes')
19926
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
1702
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1703 CheckDefFailure(['var 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
1704 enddef
d286bfc44149 patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
1705
22498
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1706 def Test_func_common_type()
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1707 def FuncOne(n: number): number
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1708 return n
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1709 enddef
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1710 def FuncTwo(s: string): number
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1711 return len(s)
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1712 enddef
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1713 def FuncThree(n: number, s: string): number
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1714 return n + len(s)
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1715 enddef
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1716 var list = [FuncOne, FuncTwo, FuncThree]
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1717 assert_equal(8, list[0](8))
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1718 assert_equal(4, list[1]('word'))
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1719 assert_equal(7, list[2](3, 'word'))
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1720 enddef
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
1721
20015
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1722 def MultiLine(
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1723 arg1: string,
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1724 arg2 = 1234,
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1725 ...rest: list<string>
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1726 ): string
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1727 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
1728 enddef
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1729
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
1730 def MultiLineComment(
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
1731 arg1: string, # comment
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
1732 arg2 = 1234, # comment
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
1733 ...rest: list<string> # comment
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
1734 ): string # comment
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
1735 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
1736 enddef
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
1737
20015
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1738 def Test_multiline()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1739 MultiLine('text')->assert_equal('text1234')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1740 MultiLine('text', 777)->assert_equal('text777')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1741 MultiLine('text', 777, 'one')->assert_equal('text777one')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1742 MultiLine('text', 777, 'one', 'two')->assert_equal('text777one-two')
20015
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1743 enddef
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1744
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
1745 func Test_multiline_not_vim9()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1746 call MultiLine('text')->assert_equal('text1234')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1747 call MultiLine('text', 777)->assert_equal('text777')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1748 call MultiLine('text', 777, 'one')->assert_equal('text777one')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1749 call MultiLine('text', 777, 'one', 'two')->assert_equal('text777one-two')
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
1750 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
1751
20015
c001ee73519a patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
1752
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1753 " 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
1754 " of E1056.
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1755 func Test_E1056_1059()
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1756 let caught_1056 = 0
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1757 try
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1758 def F():
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1759 return 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1760 enddef
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1761 catch /E1056:/
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1762 let caught_1056 = 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1763 endtry
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1764 eval caught_1056->assert_equal(1)
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1765
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1766 let caught_1059 = 0
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1767 try
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1768 def F5(items : list)
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1769 echo 'a'
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1770 enddef
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1771 catch /E1059:/
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1772 let caught_1059 = 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1773 endtry
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1774 eval caught_1059->assert_equal(1)
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19926
diff changeset
1775 endfunc
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1777 func DelMe()
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1778 echo 'DelMe'
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1779 endfunc
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1780
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1781 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
1782 # comment lines at the start of the function
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1783 var lines =<< trim END
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1784 " comment
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1785 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
1786 # comment
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1787 # comment
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1788 invalid
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1789 enddef
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1790 defcompile
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1791 END
22264
e0a4d029cb87 patch 8.2.1681: Vim9: unnessary :call commands in tests
Bram Moolenaar <Bram@vim.org>
parents: 22236
diff changeset
1792 writefile(lines, 'Xdef')
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1793 try
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1794 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
1795 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
1796 catch /E476:/
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1797 v:exception->assert_match('Invalid command: invalid')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1798 v:throwpoint->assert_match(', line 3$')
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1799 endtry
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
1800 delfunc! g:Func
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1801
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1802 # 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
1803 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
1804 " comment
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1805 def Func()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1806 var x = 1234
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1807 # comment
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1808 # comment
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1809 invalid
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1810 enddef
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1811 defcompile
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1812 END
22264
e0a4d029cb87 patch 8.2.1681: Vim9: unnessary :call commands in tests
Bram Moolenaar <Bram@vim.org>
parents: 22236
diff changeset
1813 writefile(lines, 'Xdef')
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1814 try
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1815 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
1816 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
1817 catch /E476:/
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1818 v:exception->assert_match('Invalid command: invalid')
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1819 v:throwpoint->assert_match(', line 4$')
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1820 endtry
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
1821 delfunc! g:Func
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1822
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1823 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
1824 vim9script
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1825 def Func()
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
1826 var db = {foo: 1, bar: 2}
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1827 # comment
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1828 var x = db.asdf
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1829 enddef
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1830 defcompile
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1831 Func()
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1832 END
22264
e0a4d029cb87 patch 8.2.1681: Vim9: unnessary :call commands in tests
Bram Moolenaar <Bram@vim.org>
parents: 22236
diff changeset
1833 writefile(lines, '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
1834 try
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1835 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
1836 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
1837 catch /E716:/
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1838 v:throwpoint->assert_match('_Func, line 3$')
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1839 endtry
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
1840 delfunc! g:Func
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
1841
22264
e0a4d029cb87 patch 8.2.1681: Vim9: unnessary :call commands in tests
Bram Moolenaar <Bram@vim.org>
parents: 22236
diff changeset
1842 delete('Xdef')
21685
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1843 enddef
26a4b53c4587 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines
Bram Moolenaar <Bram@vim.org>
parents: 21660
diff changeset
1844
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1845 def Test_deleted_function()
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1846 CheckDefExecFailure([
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1847 'var RefMe: func = function("g:DelMe")',
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1848 'delfunc g:DelMe',
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1849 'echo RefMe()'], 'E117:')
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1850 enddef
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1851
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1852 def Test_unknown_function()
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1853 CheckDefExecFailure([
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1854 'var 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
1855 'delfunc g:NotExist'], 'E700:')
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1856 enddef
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
1857
23531
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1858 def RefFunc(Ref: func(any): any): string
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1859 return Ref('more')
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1860 enddef
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1861
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1862 def Test_closure_simple()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1863 var local = 'some '
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
1864 RefFunc((s) => local .. s)->assert_equal('some more')
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1865 enddef
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1866
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1867 def MakeRef()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1868 var local = 'some '
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
1869 g:Ref = (s) => local .. s
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1870 enddef
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1871
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1872 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
1873 MakeRef()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1874 g:Ref('thing')->assert_equal('some thing')
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1875 unlet g:Ref
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1876 enddef
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1877
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1878 def MakeTwoRefs()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1879 var local = ['some']
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
1880 g:Extend = (s) => local->add(s)
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
1881 g:Read = () => local
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1882 enddef
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1883
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1884 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
1885 MakeTwoRefs()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1886 join(g:Read(), ' ')->assert_equal('some')
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1887 g:Extend('more')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1888 join(g:Read(), ' ')->assert_equal('some more')
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1889 g:Extend('even')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1890 join(g:Read(), ' ')->assert_equal('some more even')
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1891
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1892 unlet g:Extend
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1893 unlet g:Read
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1894 enddef
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1895
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1896 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
1897 return join(Ref(), ' ')
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1898 enddef
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1899
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22264
diff changeset
1900 def ExtendRef(Ref: func(string): list<string>, add: string)
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1901 Ref(add)
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1902 enddef
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1903
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1904 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
1905 MakeTwoRefs()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1906 ReadRef(g:Read)->assert_equal('some')
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1907 ExtendRef(g:Extend, 'more')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1908 ReadRef(g:Read)->assert_equal('some more')
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1909 ExtendRef(g:Extend, 'even')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1910 ReadRef(g:Read)->assert_equal('some more even')
20255
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1911
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1912 unlet g:Extend
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1913 unlet g:Read
aac52c32a91f patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents: 20253
diff changeset
1914 enddef
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
1915
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1916 def MakeArgRefs(theArg: string)
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1917 var local = 'loc_val'
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
1918 g:UseArg = (s) => theArg .. '/' .. local .. '/' .. s
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1919 enddef
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1920
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1921 def MakeArgRefsVarargs(theArg: string, ...rest: list<string>)
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1922 var local = 'the_loc'
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
1923 g:UseVararg = (s) => theArg .. '/' .. local .. '/' .. s .. '/' .. join(rest)
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1924 enddef
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1925
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1926 def Test_closure_using_argument()
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1927 MakeArgRefs('arg_val')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1928 g:UseArg('call_val')->assert_equal('arg_val/loc_val/call_val')
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1929
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1930 MakeArgRefsVarargs('arg_val', 'one', 'two')
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1931 g:UseVararg('call_val')->assert_equal('arg_val/the_loc/call_val/one two')
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1932
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1933 unlet g:UseArg
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1934 unlet g:UseVararg
23923
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23879
diff changeset
1935
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23879
diff changeset
1936 var lines =<< trim END
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23879
diff changeset
1937 vim9script
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23879
diff changeset
1938 def Test(Fun: func(number): number): list<number>
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23879
diff changeset
1939 return map([1, 2, 3], (_, i) => Fun(i))
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23879
diff changeset
1940 enddef
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23879
diff changeset
1941 def Inc(nr: number): number
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23879
diff changeset
1942 return nr + 2
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23879
diff changeset
1943 enddef
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23879
diff changeset
1944 assert_equal([3, 4, 5], Test(Inc))
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23879
diff changeset
1945 END
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23879
diff changeset
1946 CheckScriptSuccess(lines)
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1947 enddef
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
1948
22541
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1949 def MakeGetAndAppendRefs()
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1950 var local = 'a'
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1951
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1952 def Append(arg: string)
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1953 local ..= arg
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1954 enddef
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1955 g:Append = Append
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1956
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1957 def Get(): string
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1958 return local
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1959 enddef
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1960 g:Get = Get
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1961 enddef
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1962
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1963 def Test_closure_append_get()
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1964 MakeGetAndAppendRefs()
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1965 g:Get()->assert_equal('a')
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1966 g:Append('-b')
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1967 g:Get()->assert_equal('a-b')
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1968 g:Append('-c')
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1969 g:Get()->assert_equal('a-b-c')
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1970
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1971 unlet g:Append
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1972 unlet g:Get
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
1973 enddef
20295
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20287
diff changeset
1974
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
1975 def Test_nested_closure()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1976 var local = 'text'
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
1977 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
1978 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
1979 enddef
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1980 Closure('!!!')->assert_equal('text!!!')
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
1981 enddef
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
1982
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
1983 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
1984 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
1985 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
1986
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20355
diff changeset
1987 def Test_call_closure_not_compiled()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1988 var text = 'text'
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
1989 g:Ref = (s) => s .. text
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
1990 GetResult(g:Ref)->assert_equal('sometext')
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
1991 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
1992
22314
41e118669df3 patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error
Bram Moolenaar <Bram@vim.org>
parents: 22303
diff changeset
1993 def Test_double_closure_fails()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1994 var lines =<< trim END
22314
41e118669df3 patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error
Bram Moolenaar <Bram@vim.org>
parents: 22303
diff changeset
1995 vim9script
41e118669df3 patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error
Bram Moolenaar <Bram@vim.org>
parents: 22303
diff changeset
1996 def Func()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1997 var name = 0
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
1998 for i in range(2)
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
1999 timer_start(0, () => name)
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
2000 endfor
22314
41e118669df3 patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error
Bram Moolenaar <Bram@vim.org>
parents: 22303
diff changeset
2001 enddef
41e118669df3 patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error
Bram Moolenaar <Bram@vim.org>
parents: 22303
diff changeset
2002 Func()
41e118669df3 patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error
Bram Moolenaar <Bram@vim.org>
parents: 22303
diff changeset
2003 END
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22349
diff changeset
2004 CheckScriptSuccess(lines)
22314
41e118669df3 patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error
Bram Moolenaar <Bram@vim.org>
parents: 22303
diff changeset
2005 enddef
41e118669df3 patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error
Bram Moolenaar <Bram@vim.org>
parents: 22303
diff changeset
2006
22541
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
2007 def Test_nested_closure_used()
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
2008 var lines =<< trim END
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
2009 vim9script
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
2010 def Func()
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
2011 var x = 'hello'
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
2012 var Closure = () => x
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
2013 g:Myclosure = () => Closure()
22541
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
2014 enddef
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
2015 Func()
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
2016 assert_equal('hello', g:Myclosure())
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
2017 END
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
2018 CheckScriptSuccess(lines)
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
2019 enddef
22527
c3e3c5707fe9 patch 8.2.1812: Vim9: nested closure throws an internal error
Bram Moolenaar <Bram@vim.org>
parents: 22498
diff changeset
2020
22401
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
2021 def Test_nested_closure_fails()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
2022 var lines =<< trim END
22401
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
2023 vim9script
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
2024 def FuncA()
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
2025 FuncB(0)
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
2026 enddef
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
2027 def FuncB(n: number): list<string>
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
2028 return map([0], (_, v) => n)
22401
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
2029 enddef
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
2030 FuncA()
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
2031 END
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
2032 CheckScriptFailure(lines, 'E1012:')
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
2033 enddef
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
2034
23249
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2035 def Test_global_closure()
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2036 var lines =<< trim END
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2037 vim9script
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2038 def ReverseEveryNLines(n: number, line1: number, line2: number)
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2039 var mods = 'sil keepj keepp lockm '
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2040 var range = ':' .. line1 .. ',' .. line2
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2041 def g:Offset(): number
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2042 var offset = (line('.') - line1 + 1) % n
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2043 return offset != 0 ? offset : n
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2044 enddef
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2045 exe mods .. range .. 'g/^/exe "m .-" .. g:Offset()'
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2046 enddef
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2047
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2048 new
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2049 repeat(['aaa', 'bbb', 'ccc'], 3)->setline(1)
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2050 ReverseEveryNLines(3, 1, 9)
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2051 END
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2052 CheckScriptSuccess(lines)
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2053 var expected = repeat(['ccc', 'bbb', 'aaa'], 3)
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2054 assert_equal(expected, getline(1, 9))
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2055 bwipe!
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2056 enddef
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
2057
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2058 def Test_global_closure_called_directly()
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2059 var lines =<< trim END
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2060 vim9script
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2061 def Outer()
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2062 var x = 1
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2063 def g:Inner()
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2064 var y = x
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2065 x += 1
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2066 assert_equal(1, y)
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2067 enddef
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2068 g:Inner()
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2069 assert_equal(2, x)
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2070 enddef
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2071 Outer()
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2072 END
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2073 CheckScriptSuccess(lines)
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2074 delfunc g:Inner
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2075 enddef
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
2076
23009
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2077 def Test_failure_in_called_function()
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2078 # this was using the frame index as the return value
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2079 var lines =<< trim END
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2080 vim9script
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2081 au TerminalWinOpen * eval [][0]
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2082 def PopupTerm(a: any)
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2083 # make sure typvals on stack are string
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2084 ['a', 'b', 'c', 'd', 'e', 'f', 'g']->join()
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2085 FireEvent()
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2086 enddef
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2087 def FireEvent()
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2088 do TerminalWinOpen
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2089 enddef
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2090 # use try/catch to make eval fail
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2091 try
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2092 call PopupTerm(0)
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2093 catch
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2094 endtry
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2095 au! TerminalWinOpen
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2096 END
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2097 CheckScriptSuccess(lines)
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2098 enddef
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2099
22460
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2100 def Test_nested_lambda()
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2101 var lines =<< trim END
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2102 vim9script
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2103 def Func()
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2104 var x = 4
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
2105 var Lambda1 = () => 7
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
2106 var Lambda2 = () => [Lambda1(), x]
22460
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2107 var res = Lambda2()
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2108 assert_equal([7, 4], res)
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2109 enddef
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2110 Func()
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2111 END
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2112 CheckScriptSuccess(lines)
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2113 enddef
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22437
diff changeset
2114
24651
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2115 def Test_nested_inline_lambda()
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2116 # TODO: use the "text" argument
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2117 var lines =<< trim END
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2118 vim9script
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2119 def F(text: string): func(string): func(string): string
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2120 return (arg: string): func(string): string => ((sep: string): string => {
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2121 return sep .. arg
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2122 })
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2123 enddef
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2124 assert_equal('--there', F('unused')('there')('--'))
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2125 END
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2126 CheckScriptSuccess(lines)
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2127 enddef
5dea95170907 patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
2128
22910
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22908
diff changeset
2129 def Shadowed(): list<number>
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
2130 var FuncList: list<func: number> = [() => 42]
23565
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23559
diff changeset
2131 return FuncList->mapnew((_, Shadowed) => Shadowed())
22910
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22908
diff changeset
2132 enddef
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22908
diff changeset
2133
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22908
diff changeset
2134 def Test_lambda_arg_shadows_func()
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22908
diff changeset
2135 assert_equal([42], Shadowed())
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22908
diff changeset
2136 enddef
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22908
diff changeset
2137
20972
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
2138 def Line_continuation_in_def(dir: string = ''): string
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
2139 var path: string = empty(dir)
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
2140 \ ? 'empty'
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
2141 \ : 'full'
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
2142 return path
20972
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
2143 enddef
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
2144
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
2145 def Test_line_continuation_in_def()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2146 Line_continuation_in_def('.')->assert_equal('full')
20972
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
2147 enddef
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
2148
22942
4759d13193fb patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
2149 def Test_script_var_in_lambda()
4759d13193fb patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
2150 var lines =<< trim END
4759d13193fb patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
2151 vim9script
4759d13193fb patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
2152 var script = 'test'
24414
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2153 assert_equal(['test'], map(['one'], (_, _) => script))
22942
4759d13193fb patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
2154 END
4759d13193fb patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
2155 CheckScriptSuccess(lines)
4759d13193fb patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
2156 enddef
4759d13193fb patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
2157
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22264
diff changeset
2158 def Line_continuation_in_lambda(): list<string>
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
2159 var x = range(97, 100)
23565
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23559
diff changeset
2160 ->mapnew((_, v) => nr2char(v)
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
2161 ->toupper())
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
2162 ->reverse()
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
2163 return x
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
2164 enddef
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
2165
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
2166 def Test_line_continuation_in_lambda()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2167 Line_continuation_in_lambda()->assert_equal(['D', 'C', 'B', 'A'])
23644
03acf9c49f07 patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents: 23630
diff changeset
2168
03acf9c49f07 patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents: 23630
diff changeset
2169 var lines =<< trim END
03acf9c49f07 patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents: 23630
diff changeset
2170 vim9script
03acf9c49f07 patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents: 23630
diff changeset
2171 var res = [{n: 1, m: 2, s: 'xxx'}]
03acf9c49f07 patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents: 23630
diff changeset
2172 ->mapnew((_, v: dict<any>): string => printf('%d:%d:%s',
03acf9c49f07 patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents: 23630
diff changeset
2173 v.n,
03acf9c49f07 patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents: 23630
diff changeset
2174 v.m,
03acf9c49f07 patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents: 23630
diff changeset
2175 substitute(v.s, '.*', 'yyy', '')
03acf9c49f07 patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents: 23630
diff changeset
2176 ))
03acf9c49f07 patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents: 23630
diff changeset
2177 assert_equal(['1:2:yyy'], res)
03acf9c49f07 patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents: 23630
diff changeset
2178 END
03acf9c49f07 patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents: 23630
diff changeset
2179 CheckScriptSuccess(lines)
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
2180 enddef
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21186
diff changeset
2181
23547
7f09cfa9ac4a patch 8.2.2316: Vim9: cannot list a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 23545
diff changeset
2182 def Test_list_lambda()
7f09cfa9ac4a patch 8.2.2316: Vim9: cannot list a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 23545
diff changeset
2183 timer_start(1000, (_) => 0)
7f09cfa9ac4a patch 8.2.2316: Vim9: cannot list a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 23545
diff changeset
2184 var body = execute(timer_info()[0].callback
7f09cfa9ac4a patch 8.2.2316: Vim9: cannot list a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 23545
diff changeset
2185 ->string()
7f09cfa9ac4a patch 8.2.2316: Vim9: cannot list a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 23545
diff changeset
2186 ->substitute("('", ' ', '')
7f09cfa9ac4a patch 8.2.2316: Vim9: cannot list a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 23545
diff changeset
2187 ->substitute("')", '', '')
7f09cfa9ac4a patch 8.2.2316: Vim9: cannot list a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 23545
diff changeset
2188 ->substitute('function\zs', ' ', ''))
24398
bed5ec739304 patch 8.2.2739: Vim9: a lambda accepts too many arguments at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24371
diff changeset
2189 assert_match('def <lambda>\d\+(_: any): number\n1 return 0\n enddef', body)
23547
7f09cfa9ac4a patch 8.2.2316: Vim9: cannot list a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 23545
diff changeset
2190 enddef
7f09cfa9ac4a patch 8.2.2316: Vim9: cannot list a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 23545
diff changeset
2191
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24525
diff changeset
2192 def Test_legacy_lambda()
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24525
diff changeset
2193 legacy echo {x -> 'hello ' .. x}('foo')
24539
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2194
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24525
diff changeset
2195 var lines =<< trim END
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24525
diff changeset
2196 echo {x -> 'hello ' .. x}('foo')
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24525
diff changeset
2197 END
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24525
diff changeset
2198 CheckDefAndScriptFailure(lines, 'E720:')
24539
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2199
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2200 lines =<< trim END
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2201 vim9script
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2202 def Func()
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2203 echo (() => 'no error')()
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2204 enddef
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2205 legacy call s:Func()
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2206 END
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2207 CheckScriptSuccess(lines)
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24525
diff changeset
2208 enddef
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24525
diff changeset
2209
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23547
diff changeset
2210 def DoFilterThis(a: string): list<string>
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23547
diff changeset
2211 # closure nested inside another closure using argument
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23547
diff changeset
2212 var Filter = (l) => filter(l, (_, v) => stridx(v, a) == 0)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23547
diff changeset
2213 return ['x', 'y', 'a', 'x2', 'c']->Filter()
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23547
diff changeset
2214 enddef
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23547
diff changeset
2215
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23547
diff changeset
2216 def Test_nested_closure_using_argument()
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23547
diff changeset
2217 assert_equal(['x', 'x2'], DoFilterThis('x'))
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23547
diff changeset
2218 enddef
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23547
diff changeset
2219
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2220 def Test_triple_nested_closure()
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2221 var what = 'x'
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2222 var Match = (val: string, cmp: string): bool => stridx(val, cmp) == 0
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2223 var Filter = (l) => filter(l, (_, v) => Match(v, what))
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2224 assert_equal(['x', 'x2'], ['x', 'y', 'a', 'x2', 'c']->Filter())
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2225 enddef
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2226
21176
54c665ad2db3 patch 8.2.1139: Vim9: test for silent echo fails in some environments
Bram Moolenaar <Bram@vim.org>
parents: 21174
diff changeset
2227 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
2228 CheckScreendump
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
2229
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
2230 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
2231 vim9script
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
2232 def EchoNothing()
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
2233 silent echo ''
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
2234 enddef
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
2235 defcompile
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
2236 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
2237 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
2238
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
2239 " 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
2240 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
2241 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
2242 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
2243
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
2244 " clean up
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
2245 call StopVimInTerminal(buf)
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
2246 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
2247 endfunc
21172
96ae8622cfb6 patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents: 21170
diff changeset
2248
22736
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2249 def SilentlyError()
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2250 execute('silent! invalid')
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2251 g:did_it = 'yes'
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2252 enddef
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2253
22742
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
2254 func UserError()
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
2255 silent! invalid
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
2256 endfunc
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
2257
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
2258 def SilentlyUserError()
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
2259 UserError()
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
2260 g:did_it = 'yes'
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
2261 enddef
22736
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2262
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2263 " This can't be a :def function, because the assert would not be reached.
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2264 func Test_ignore_silent_error()
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2265 let g:did_it = 'no'
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2266 call SilentlyError()
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2267 call assert_equal('yes', g:did_it)
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2268
22742
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
2269 let g:did_it = 'no'
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
2270 call SilentlyUserError()
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
2271 call assert_equal('yes', g:did_it)
22736
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2272
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2273 unlet g:did_it
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2274 endfunc
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
2275
22760
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2276 def Test_ignore_silent_error_in_filter()
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2277 var lines =<< trim END
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2278 vim9script
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2279 def Filter(winid: number, key: string): bool
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2280 if key == 'o'
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2281 silent! eval [][0]
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2282 return true
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2283 endif
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2284 return popup_filter_menu(winid, key)
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2285 enddef
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2286
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
2287 popup_create('popup', {filter: Filter})
22760
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2288 feedkeys("o\r", 'xnt')
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2289 END
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2290 CheckScriptSuccess(lines)
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2291 enddef
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
2292
22135
f45127fbe9ba patch 8.2.1617: Vim9: cannot pass "true" to win_splitmove()
Bram Moolenaar <Bram@vim.org>
parents: 22133
diff changeset
2293 def Fibonacci(n: number): number
f45127fbe9ba patch 8.2.1617: Vim9: cannot pass "true" to win_splitmove()
Bram Moolenaar <Bram@vim.org>
parents: 22133
diff changeset
2294 if n < 2
f45127fbe9ba patch 8.2.1617: Vim9: cannot pass "true" to win_splitmove()
Bram Moolenaar <Bram@vim.org>
parents: 22133
diff changeset
2295 return n
f45127fbe9ba patch 8.2.1617: Vim9: cannot pass "true" to win_splitmove()
Bram Moolenaar <Bram@vim.org>
parents: 22133
diff changeset
2296 else
f45127fbe9ba patch 8.2.1617: Vim9: cannot pass "true" to win_splitmove()
Bram Moolenaar <Bram@vim.org>
parents: 22133
diff changeset
2297 return Fibonacci(n - 1) + Fibonacci(n - 2)
f45127fbe9ba patch 8.2.1617: Vim9: cannot pass "true" to win_splitmove()
Bram Moolenaar <Bram@vim.org>
parents: 22133
diff changeset
2298 endif
f45127fbe9ba patch 8.2.1617: Vim9: cannot pass "true" to win_splitmove()
Bram Moolenaar <Bram@vim.org>
parents: 22133
diff changeset
2299 enddef
f45127fbe9ba patch 8.2.1617: Vim9: cannot pass "true" to win_splitmove()
Bram Moolenaar <Bram@vim.org>
parents: 22133
diff changeset
2300
21281
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
2301 def Test_recursive_call()
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2302 Fibonacci(20)->assert_equal(6765)
21281
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
2303 enddef
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
2304
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
2305 def TreeWalk(dir: string): list<any>
23565
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23559
diff changeset
2306 return readdir(dir)->mapnew((_, 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
2307 fnamemodify(dir .. '/' .. val, ':p')->isdirectory()
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22910
diff changeset
2308 ? {[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
2309 : val
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
2310 )
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
2311 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
2312
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
2313 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
2314 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
2315 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
2316 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
2317 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
2318
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
2319 TreeWalk('XclosureDir')->assert_equal(['file1', 'file2', {tdir: ['file3']}])
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
2320
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
2321 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
2322 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
2323
22496
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2324 def Test_invalid_function_name()
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2325 var lines =<< trim END
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2326 vim9script
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2327 def s: list<string>
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2328 END
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2329 CheckScriptFailure(lines, 'E129:')
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2330
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2331 lines =<< trim END
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2332 vim9script
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2333 def g: list<string>
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2334 END
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2335 CheckScriptFailure(lines, 'E129:')
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2336
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2337 lines =<< trim END
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2338 vim9script
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2339 def <SID>: list<string>
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2340 END
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2341 CheckScriptFailure(lines, 'E884:')
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2342
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2343 lines =<< trim END
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2344 vim9script
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2345 def F list<string>
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2346 END
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2347 CheckScriptFailure(lines, 'E488:')
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2348 enddef
454b78ca8247 patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents: 22468
diff changeset
2349
21347
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
2350 def Test_partial_call()
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
2351 var Xsetlist = function('setloclist', [0])
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
2352 Xsetlist([], ' ', {title: 'test'})
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
2353 getloclist(0, {title: 1})->assert_equal({title: 'test'})
21347
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
2354
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
2355 Xsetlist = function('setloclist', [0, [], ' '])
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
2356 Xsetlist({title: 'test'})
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
2357 getloclist(0, {title: 1})->assert_equal({title: 'test'})
21347
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
2358
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
2359 Xsetlist = function('setqflist')
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
2360 Xsetlist([], ' ', {title: 'test'})
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
2361 getqflist({title: 1})->assert_equal({title: 'test'})
21347
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
2362
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
2363 Xsetlist = function('setqflist', [[], ' '])
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
2364 Xsetlist({title: 'test'})
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
2365 getqflist({title: 1})->assert_equal({title: 'test'})
22498
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
2366
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
2367 var Len: func: number = function('len', ['word'])
04a9b1399d8e patch 8.2.1797: Vim9: some parts of the code not tested
Bram Moolenaar <Bram@vim.org>
parents: 22496
diff changeset
2368 assert_equal(4, Len())
21347
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
2369 enddef
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
2370
21689
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2371 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
2372 tab echo '0'
22147
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 22139
diff changeset
2373 CheckDefFailure(['5tab echo 3'], 'E16:')
21689
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2374 enddef
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2375
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2376 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
2377 # 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
2378 # up.
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
2379 var lines =<< trim END
21689
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2380 vim9script
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2381 set eventignore=
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2382 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
2383 def AutocmdsDisabled()
22734
02b782e80ee4 patch 8.2.1915: Vim9: error for wrong number of arguments is not useful
Bram Moolenaar <Bram@vim.org>
parents: 22655
diff changeset
2384 eval 0
21689
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2385 enddef
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2386 func Func()
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2387 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
2388 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
2389 endfunc
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2390 Func()
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2391 END
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2392 CheckScriptSuccess(lines)
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2393 g:ei_after->assert_equal('')
21689
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2394 enddef
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21685
diff changeset
2395
22214
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2396 def StackTop()
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2397 eval 1
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2398 eval 2
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2399 # call not on fourth line
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2400 StackBot()
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2401 enddef
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2402
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2403 def StackBot()
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2404 # throw an error
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2405 eval [][0]
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2406 enddef
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2407
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2408 def Test_callstack_def()
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2409 try
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2410 StackTop()
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2411 catch
22222
7b9e8fd7ea5b patch 8.2.1660: assert functions require passing expected as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2412 v:throwpoint->assert_match('Test_callstack_def\[2\]..StackTop\[4\]..StackBot, line 2')
22214
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2413 endtry
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2414 enddef
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22165
diff changeset
2415
22537
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2416 " Re-using spot for variable used in block
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2417 def Test_block_scoped_var()
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2418 var lines =<< trim END
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2419 vim9script
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2420 def Func()
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2421 var x = ['a', 'b', 'c']
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2422 if 1
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2423 var y = 'x'
24414
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2424 map(x, (_, _) => y)
22537
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2425 endif
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2426 var z = x
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2427 assert_equal(['x', 'x', 'x'], z)
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2428 enddef
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2429 Func()
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2430 END
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2431 CheckScriptSuccess(lines)
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2432 enddef
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22535
diff changeset
2433
22948
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2434 def Test_reset_did_emsg()
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2435 var lines =<< trim END
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2436 @s = 'blah'
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2437 au BufWinLeave * #
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2438 def Func()
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2439 var winid = popup_create('popup', {})
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2440 exe '*s'
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2441 popup_close(winid)
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2442 enddef
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2443 Func()
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2444 END
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2445 CheckScriptFailure(lines, 'E492:', 8)
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
2446 delfunc! g:Func
22948
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2447 enddef
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22942
diff changeset
2448
23177
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2449 def Test_did_emsg_reset()
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2450 # executing an autocommand resets did_emsg, this should not result in a
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2451 # builtin function considered failing
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2452 var lines =<< trim END
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2453 vim9script
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2454 au BufWinLeave * #
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2455 def Func()
24398
bed5ec739304 patch 8.2.2739: Vim9: a lambda accepts too many arguments at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24371
diff changeset
2456 popup_menu('', {callback: (a, b) => popup_create('', {})->popup_close()})
23177
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2457 eval [][0]
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2458 enddef
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2459 nno <F3> <cmd>call <sid>Func()<cr>
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2460 feedkeys("\<F3>\e", 'xt')
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2461 END
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2462 writefile(lines, 'XemsgReset')
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2463 assert_fails('so XemsgReset', ['E684:', 'E684:'], lines, 2)
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2464 delete('XemsgReset')
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2465 nunmap <F3>
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2466 au! BufWinLeave
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2467 enddef
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
2468
23102
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2469 def Test_abort_with_silent_call()
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2470 var lines =<< trim END
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2471 vim9script
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2472 g:result = 'none'
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2473 def Func()
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2474 g:result += 3
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2475 g:result = 'yes'
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2476 enddef
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2477 # error is silenced, but function aborts on error
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2478 silent! Func()
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2479 assert_equal('none', g:result)
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2480 unlet g:result
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2481 END
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2482 CheckScriptSuccess(lines)
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2483 enddef
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2484
23100
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2485 def Test_continues_with_silent_error()
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2486 var lines =<< trim END
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2487 vim9script
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2488 g:result = 'none'
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2489 def Func()
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2490 silent! g:result += 3
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2491 g:result = 'yes'
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2492 enddef
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2493 # error is silenced, function does not abort
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2494 Func()
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2495 assert_equal('yes', g:result)
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2496 unlet g:result
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2497 END
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2498 CheckScriptSuccess(lines)
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2499 enddef
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2500
23074
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2501 def Test_abort_even_with_silent()
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2502 var lines =<< trim END
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2503 vim9script
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2504 g:result = 'none'
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2505 def Func()
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2506 eval {-> ''}() .. '' .. {}['X']
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2507 g:result = 'yes'
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2508 enddef
23100
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2509 silent! Func()
23074
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2510 assert_equal('none', g:result)
23098
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2511 unlet g:result
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2512 END
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2513 CheckScriptSuccess(lines)
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2514 enddef
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2515
23100
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2516 def Test_cmdmod_silent_restored()
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2517 var lines =<< trim END
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2518 vim9script
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2519 def Func()
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2520 g:result = 'none'
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2521 silent! g:result += 3
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2522 g:result = 'none'
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2523 g:result += 3
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2524 enddef
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2525 Func()
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2526 END
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2527 # can't use CheckScriptFailure, it ignores the :silent!
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2528 var fname = 'Xdefsilent'
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2529 writefile(lines, fname)
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2530 var caught = 'no'
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2531 try
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2532 exe 'source ' .. fname
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2533 catch /E1030:/
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2534 caught = 'yes'
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2535 assert_match('Func, line 4', v:throwpoint)
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2536 endtry
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2537 assert_equal('yes', caught)
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2538 delete(fname)
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2539 enddef
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
2540
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2541 def Test_cmdmod_silent_nested()
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2542 var lines =<< trim END
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2543 vim9script
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2544 var result = ''
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2545
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2546 def Error()
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2547 result ..= 'Eb'
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2548 eval [][0]
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2549 result ..= 'Ea'
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2550 enddef
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2551
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2552 def Crash()
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2553 result ..= 'Cb'
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2554 sil! Error()
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2555 result ..= 'Ca'
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2556 enddef
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2557
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2558 Crash()
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2559 assert_equal('CbEbEaCa', result)
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2560 END
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2561 CheckScriptSuccess(lines)
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2562 enddef
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24208
diff changeset
2563
23098
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2564 def Test_dict_member_with_silent()
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2565 var lines =<< trim END
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2566 vim9script
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2567 g:result = 'none'
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2568 var d: dict<any>
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2569 def Func()
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2570 try
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23426
diff changeset
2571 g:result = map([], (_, v) => ({}[v]))->join() .. d['']
23098
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2572 catch
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2573 endtry
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2574 enddef
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2575 silent! Func()
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2576 assert_equal('0', g:result)
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
2577 unlet g:result
23074
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2578 END
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2579 CheckScriptSuccess(lines)
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2580 enddef
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2581
23689
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2582 def Test_skip_cmds_with_silent()
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2583 var lines =<< trim END
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2584 vim9script
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2585
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2586 def Func(b: bool)
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2587 Crash()
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2588 enddef
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2589
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2590 def Crash()
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2591 sil! :/not found/d _
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2592 sil! :/not found/put _
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2593 enddef
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2594
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2595 Func(true)
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2596 END
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2597 CheckScriptSuccess(lines)
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2598 enddef
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23644
diff changeset
2599
23281
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2600 def Test_opfunc()
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2601 nnoremap <F3> <cmd>set opfunc=Opfunc<cr>g@
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2602 def g:Opfunc(_: any): string
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2603 setline(1, 'ASDF')
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2604 return ''
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2605 enddef
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2606 new
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2607 setline(1, 'asdf')
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2608 feedkeys("\<F3>$", 'x')
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2609 assert_equal('ASDF', getline(1))
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2610
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2611 bwipe!
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2612 nunmap <F3>
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2613 enddef
5b4db8035d1d patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
2614
23289
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2615 " this was crashing on exit
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2616 def Test_nested_lambda_in_closure()
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2617 var lines =<< trim END
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2618 vim9script
24555
83877a1b66fd patch 8.2.2817: Vim9: script sourcing continues after an error
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
2619 command WriteDone writefile(['Done'], 'XnestedDone')
23289
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2620 def Outer()
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2621 def g:Inner()
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2622 echo map([1, 2, 3], {_, v -> v + 1})
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2623 enddef
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2624 g:Inner()
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2625 enddef
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2626 defcompile
24555
83877a1b66fd patch 8.2.2817: Vim9: script sourcing continues after an error
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
2627 # not reached
23289
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2628 END
24555
83877a1b66fd patch 8.2.2817: Vim9: script sourcing continues after an error
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
2629 if !RunVim([], lines, '--clean -c WriteDone -c quit')
23289
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2630 return
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2631 endif
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2632 assert_equal(['Done'], readfile('XnestedDone'))
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2633 delete('XnestedDone')
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2634 enddef
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2635
24065
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2636 def Test_check_func_arg_types()
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2637 var lines =<< trim END
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2638 vim9script
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2639 def F1(x: string): string
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2640 return x
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2641 enddef
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2642
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2643 def F2(x: number): number
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2644 return x + 1
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2645 enddef
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2646
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2647 def G(g: func): dict<func>
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2648 return {f: g}
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2649 enddef
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2650
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2651 def H(d: dict<func>): string
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2652 return d.f('a')
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2653 enddef
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2654 END
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2655
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2656 CheckScriptSuccess(lines + ['echo H(G(F1))'])
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2657 CheckScriptFailure(lines + ['echo H(G(F2))'], 'E1013:')
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2658 enddef
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
2659
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2660 def Test_compile_error()
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2661 var lines =<< trim END
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2662 def g:Broken()
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2663 echo 'a' + {}
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2664 enddef
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2665 call g:Broken()
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2666 END
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2667 # First call: compilation error
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2668 CheckScriptFailure(lines, 'E1051: Wrong argument type for +')
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2669
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2670 # Second call won't try compiling again
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2671 assert_fails('call g:Broken()', 'E1091: Function is not compiled: Broken')
24406
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2672 delfunc g:Broken
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2673
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2674 # No error when compiling with :silent!
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2675 lines =<< trim END
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2676 def g:Broken()
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2677 echo 'a' + []
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2678 enddef
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2679 silent! defcompile
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2680 END
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2681 CheckScriptSuccess(lines)
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2682
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2683 # Calling the function won't try compiling again
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2684 assert_fails('call g:Broken()', 'E1091: Function is not compiled: Broken')
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
2685 delfunc g:Broken
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2686 enddef
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
2687
24408
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2688 def Test_ignored_argument()
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2689 var lines =<< trim END
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2690 vim9script
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2691 def Ignore(_, _): string
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2692 return 'yes'
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2693 enddef
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2694 assert_equal('yes', Ignore(1, 2))
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2695
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2696 func Ok(_)
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2697 return a:_
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2698 endfunc
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2699 assert_equal('ok', Ok('ok'))
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2700
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2701 func Oktoo()
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2702 let _ = 'too'
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2703 return _
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2704 endfunc
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2705 assert_equal('too', Oktoo())
24420
e0fa539a9b34 patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24414
diff changeset
2706
e0fa539a9b34 patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24414
diff changeset
2707 assert_equal([[1], [2], [3]], range(3)->mapnew((_, v) => [v]->map((_, w) => w + 1)))
24408
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2708 END
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2709 CheckScriptSuccess(lines)
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2710
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2711 lines =<< trim END
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2712 def Ignore(_: string): string
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2713 return _
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2714 enddef
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2715 defcompile
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2716 END
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2717 CheckScriptFailure(lines, 'E1181:', 1)
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2718
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2719 lines =<< trim END
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2720 var _ = 1
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2721 END
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2722 CheckDefAndScriptFailure(lines, 'E1181:', 1)
24695
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
2723
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
2724 lines =<< trim END
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
2725 var x = _
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
2726 END
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
2727 CheckDefAndScriptFailure(lines, 'E1181:', 1)
24408
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2728 enddef
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
2729
24414
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2730 def Test_too_many_arguments()
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2731 var lines =<< trim END
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2732 echo [0, 1, 2]->map(() => 123)
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2733 END
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2734 CheckDefExecAndScriptFailure(lines, 'E1106: 2 arguments too many', 1)
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2735
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2736 lines =<< trim END
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2737 echo [0, 1, 2]->map((_) => 123)
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2738 END
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2739 CheckDefExecAndScriptFailure(lines, 'E1106: One argument too many', 1)
f539864ba851 patch 8.2.2747: Vim9: not always an error for too many function arguments
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
2740 enddef
23289
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
2741
24525
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24436
diff changeset
2742 def Test_closing_brace_at_start_of_line()
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24436
diff changeset
2743 var lines =<< trim END
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24436
diff changeset
2744 def Func()
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24436
diff changeset
2745 enddef
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24436
diff changeset
2746 Func(
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24436
diff changeset
2747 )
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24436
diff changeset
2748 END
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24436
diff changeset
2749 call CheckDefAndScriptSuccess(lines)
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24436
diff changeset
2750 enddef
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24436
diff changeset
2751
20257
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20255
diff changeset
2752
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2753 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker