summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-04-25 20:02:55 +0200
committerBram Moolenaar <Bram@vim.org>2020-04-25 20:02:55 +0200
commitcfe435d7feacf123ac060747b885f7c4328062ea (patch)
treef97da740c86f5fb5e9c7cedeb7b48c26ebf5ac47
parent49b2fb36ca94be14b98caf86420863d9bbe81a24 (diff)
downloadvim-git-cfe435d7feacf123ac060747b885f7c4328062ea.tar.gz
patch 8.2.0640: Vim9: expanding does not workv8.2.0640
Problem: Vim9: expanding does not work. Solution: Find wildcards in not compiled commands. Reorganize test files.
-rw-r--r--Filelist1
-rw-r--r--src/testdir/Make_all.mak2
-rw-r--r--src/testdir/test_vim9_cmd.vim23
-rw-r--r--src/testdir/test_vim9_disassemble.vim26
-rw-r--r--src/testdir/test_vim9_expr.vim362
-rw-r--r--src/testdir/test_vim9_script.vim20
-rw-r--r--src/testdir/vim9.vim28
-rw-r--r--src/version.c2
-rw-r--r--src/vim9.h1
-rw-r--r--src/vim9compile.c93
-rw-r--r--src/vim9execute.c43
11 files changed, 380 insertions, 221 deletions
diff --git a/Filelist b/Filelist
index 581a72d1a..ff5994ba0 100644
--- a/Filelist
+++ b/Filelist
@@ -162,6 +162,7 @@ SRC_ALL = \
src/testdir/setup.vim \
src/testdir/setup_gui.vim \
src/testdir/shared.vim \
+ src/testdir/vim9.vim \
src/testdir/summarize.vim \
src/testdir/term_util.vim \
src/testdir/view_util.vim \
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index db74f05a3..772c08334 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -45,12 +45,14 @@ SCRIPTS_GUI =
# Tests for Vim9 script.
TEST_VIM9 = \
+ test_vim9_cmd \
test_vim9_disassemble \
test_vim9_expr \
test_vim9_func \
test_vim9_script
TEST_VIM9_RES = \
+ test_vim9_cmd.res \
test_vim9_disassemble.res \
test_vim9_expr.res \
test_vim9_func.res \
diff --git a/src/testdir/test_vim9_cmd.vim b/src/testdir/test_vim9_cmd.vim
new file mode 100644
index 000000000..7ccd1f70c
--- /dev/null
+++ b/src/testdir/test_vim9_cmd.vim
@@ -0,0 +1,23 @@
+" Test commands that are not compiled in a :def function
+
+source vim9.vim
+
+def Test_edit_wildcards()
+ let filename = 'Xtest'
+ edit `=filename`
+ assert_equal('Xtest', bufname())
+
+ let filenr = 123
+ edit Xtest`=filenr`
+ assert_equal('Xtest123', bufname())
+
+ filenr = 77
+ edit `=filename``=filenr`
+ assert_equal('Xtest77', bufname())
+
+ edit X`=filename`xx`=filenr`yy
+ assert_equal('XXtestxx77yy', bufname())
+enddef
+
+
+" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim
index 89ca66f11..4e2caf09f 100644
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -53,6 +53,32 @@ def Test_disassemble_load()
res)
enddef
+def s:EditExpand()
+ let filename = "file"
+ let filenr = 123
+ edit the`=filename``=filenr`.txt
+enddef
+
+def Test_disassemble_exec_expr()
+ let res = execute('disass s:EditExpand')
+ assert_match('<SNR>\d*_EditExpand.*' ..
+ ' let filename = "file".*' ..
+ '\d PUSHS "file".*' ..
+ '\d STORE $0.*' ..
+ ' let filenr = 123.*' ..
+ '\d STORE 123 in $1.*' ..
+ ' edit the`=filename``=filenr`.txt.*' ..
+ '\d PUSHS "edit the".*' ..
+ '\d LOAD $0.*' ..
+ '\d LOAD $1.*' ..
+ '\d 2STRING stack\[-1\].*' ..
+ '\d PUSHS ".txt".*' ..
+ '\d EXECCONCAT 4.*' ..
+ '\d PUSHNR 0.*' ..
+ '\d RETURN',
+ res)
+enddef
+
def s:ScriptFuncPush()
let localbool = true
let localspec = v:none
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index fe3752c8c..42a99261f 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -1,33 +1,7 @@
" Tests for Vim9 script expressions
source check.vim
-
-" Check that "line" inside ":def" results in an "error" message.
-func CheckDefFailure(line, error)
- call writefile(['def! Func()', a:line, 'enddef'], 'Xdef')
- call assert_fails('so Xdef', a:error, a:line)
- call delete('Xdef')
-endfunc
-
-func CheckDefFailureMult(lines, error)
- call writefile(['def! Func()'] + a:lines + ['enddef'], 'Xdef')
- call assert_fails('so Xdef', a:error, join(a:lines, ' | '))
- call delete('Xdef')
-endfunc
-
-" Check that "line" inside ":def" results in an "error" message when executed.
-func CheckDefExecFailure(line, error)
- call writefile(['def! Func()', a:line, 'enddef'], 'Xdef')
- so Xdef
- call assert_fails('call Func()', a:error, a:line)
- call delete('Xdef')
-endfunc
-
-func CheckDefFailureList(lines, error)
- call writefile(['def! Func()'] + a:lines + ['enddef'], 'Xdef')
- call assert_fails('so Xdef', a:error, string(a:lines))
- call delete('Xdef')
-endfunc
+source vim9.vim
" test cond ? expr : expr
def Test_expr1()
@@ -59,18 +33,18 @@ def Test_expr1()
enddef
func Test_expr1_fails()
- call CheckDefFailure("let x = 1 ? 'one'", "Missing ':' after '?'")
- call CheckDefFailure("let x = 1 ? 'one' : xxx", "E1001:")
+ call CheckDefFailure(["let x = 1 ? 'one'"], "Missing ':' after '?'")
+ call CheckDefFailure(["let x = 1 ? 'one' : xxx"], "E1001:")
let msg = "white space required before and after '?'"
- call CheckDefFailure("let x = 1? 'one' : 'two'", msg)
- call CheckDefFailure("let x = 1 ?'one' : 'two'", msg)
- call CheckDefFailure("let x = 1?'one' : 'two'", msg)
+ call CheckDefFailure(["let x = 1? 'one' : 'two'"], msg)
+ call CheckDefFailure(["let x = 1 ?'one' : 'two'"], msg)
+ call CheckDefFailure(["let x = 1?'one' : 'two'"], msg)
let msg = "white space required before and after ':'"
- call CheckDefFailure("let x = 1 ? 'one': 'two'", msg)
- call CheckDefFailure("let x = 1 ? 'one' :'two'", msg)
- call CheckDefFailure("let x = 1 ? 'one':'two'", msg)
+ call CheckDefFailure(["let x = 1 ? 'one': 'two'"], msg)
+ call CheckDefFailure(["let x = 1 ? 'one' :'two'"], msg)
+ call CheckDefFailure(["let x = 1 ? 'one':'two'"], msg)
endfunc
" TODO: define inside test function
@@ -107,11 +81,11 @@ enddef
func Test_expr2_fails()
let msg = "white space required before and after '||'"
- call CheckDefFailure("let x = 1||2", msg)
- call CheckDefFailure("let x = 1 ||2", msg)
- call CheckDefFailure("let x = 1|| 2", msg)
+ call CheckDefFailure(["let x = 1||2"], msg)
+ call CheckDefFailure(["let x = 1 ||2"], msg)
+ call CheckDefFailure(["let x = 1|| 2"], msg)
- call CheckDefFailure("let x = 1 || xxx", 'E1001:')
+ call CheckDefFailure(["let x = 1 || xxx"], 'E1001:')
endfunc
" test &&
@@ -148,9 +122,9 @@ enddef
func Test_expr3_fails()
let msg = "white space required before and after '&&'"
- call CheckDefFailure("let x = 1&&2", msg)
- call CheckDefFailure("let x = 1 &&2", msg)
- call CheckDefFailure("let x = 1&& 2", msg)
+ call CheckDefFailure(["let x = 1&&2"], msg)
+ call CheckDefFailure(["let x = 1 &&2"], msg)
+ call CheckDefFailure(["let x = 1&& 2"], msg)
endfunc
let atrue = v:true
@@ -212,7 +186,7 @@ def Test_expr4_equal()
assert_equal(false, 'abc' ==# 'ABC')
set noignorecase
- call CheckDefFailure("let x = 'a' == xxx", 'E1001:')
+ call CheckDefFailure(["let x = 'a' == xxx"], 'E1001:')
assert_equal(true, 0z3f == 0z3f)
assert_equal(false, 0z3f == 0z4f)
@@ -413,71 +387,71 @@ enddef
func Test_expr4_fails()
let msg = "white space required before and after '>'"
- call CheckDefFailure("let x = 1>2", msg)
- call CheckDefFailure("let x = 1 >2", msg)
- call CheckDefFailure("let x = 1> 2", msg)
+ call CheckDefFailure(["let x = 1>2"], msg)
+ call CheckDefFailure(["let x = 1 >2"], msg)
+ call CheckDefFailure(["let x = 1> 2"], msg)
let msg = "white space required before and after '=='"
- call CheckDefFailure("let x = 1==2", msg)
- call CheckDefFailure("let x = 1 ==2", msg)
- call CheckDefFailure("let x = 1== 2", msg)
+ call CheckDefFailure(["let x = 1==2"], msg)
+ call CheckDefFailure(["let x = 1 ==2"], msg)
+ call CheckDefFailure(["let x = 1== 2"], msg)
let msg = "white space required before and after 'is'"
- call CheckDefFailure("let x = '1'is'2'", msg)
- call CheckDefFailure("let x = '1' is'2'", msg)
- call CheckDefFailure("let x = '1'is '2'", msg)
+ call CheckDefFailure(["let x = '1'is'2'"], msg)
+ call CheckDefFailure(["let x = '1' is'2'"], msg)
+ call CheckDefFailure(["let x = '1'is '2'"], msg)
let msg = "white space required before and after 'isnot'"
- call CheckDefFailure("let x = '1'isnot'2'", msg)
- call CheckDefFailure("let x = '1' isnot'2'", msg)
- call CheckDefFailure("let x = '1'isnot '2'", msg)
-
- call CheckDefFailure("let x = 1 is# 2", 'E15:')
- call CheckDefFailure("let x = 1 is? 2", 'E15:')
- call CheckDefFailure("let x = 1 isnot# 2", 'E15:')
- call CheckDefFailure("let x = 1 isnot? 2", 'E15:')
-
- call CheckDefFailure("let x = 1 == '2'", 'Cannot compare number with string')
- call CheckDefFailure("let x = '1' == 2", 'Cannot compare string with number')
- call CheckDefFailure("let x = 1 == RetVoid()", 'Cannot use void value')
- call CheckDefFailure("let x = RetVoid() == 1", 'Cannot compare void with number')
-
- call CheckDefFailure("let x = true > false", 'Cannot compare bool with bool')
- call CheckDefFailure("let x = true >= false", 'Cannot compare bool with bool')
- call CheckDefFailure("let x = true < false", 'Cannot compare bool with bool')
- call CheckDefFailure("let x = true <= false", 'Cannot compare bool with bool')
- call CheckDefFailure("let x = true =~ false", 'Cannot compare bool with bool')
- call CheckDefFailure("let x = true !~ false", 'Cannot compare bool with bool')
- call CheckDefFailure("let x = true is false", 'Cannot use "is" with bool')
- call CheckDefFailure("let x = true isnot false", 'Cannot use "isnot" with bool')
-
- call CheckDefFailure("let x = v:none is v:null", 'Cannot use "is" with special')
- call CheckDefFailure("let x = v:none isnot v:null", 'Cannot use "isnot" with special')
- call CheckDefFailure("let x = 123 is 123", 'Cannot use "is" with number')
- call CheckDefFailure("let x = 123 isnot 123", 'Cannot use "isnot" with number')
+ call CheckDefFailure(["let x = '1'isnot'2'"], msg)
+ call CheckDefFailure(["let x = '1' isnot'2'"], msg)
+ call CheckDefFailure(["let x = '1'isnot '2'"], msg)
+
+ call CheckDefFailure(["let x = 1 is# 2"], 'E15:')
+ call CheckDefFailure(["let x = 1 is? 2"], 'E15:')
+ call CheckDefFailure(["let x = 1 isnot# 2"], 'E15:')
+ call CheckDefFailure(["let x = 1 isnot? 2"], 'E15:')
+
+ call CheckDefFailure(["let x = 1 == '2'"], 'Cannot compare number with string')
+ call CheckDefFailure(["let x = '1' == 2"], 'Cannot compare string with number')
+ call CheckDefFailure(["let x = 1 == RetVoid()"], 'Cannot use void value')
+ call CheckDefFailure(["let x = RetVoid() == 1"], 'Cannot compare void with number')
+
+ call CheckDefFailure(["let x = true > false"], 'Cannot compare bool with bool')
+ call CheckDefFailure(["let x = true >= false"], 'Cannot compare bool with bool')
+ call CheckDefFailure(["let x = true < false"], 'Cannot compare bool with bool')
+ call CheckDefFailure(["let x = true <= false"], 'Cannot compare bool with bool')
+ call CheckDefFailure(["let x = true =~ false"], 'Cannot compare bool with bool')
+ call CheckDefFailure(["let x = true !~ false"], 'Cannot compare bool with bool')
+ call CheckDefFailure(["let x = true is false"], 'Cannot use "is" with bool')
+ call CheckDefFailure(["let x = true isnot false"], 'Cannot use "isnot" with bool')
+
+ call CheckDefFailure(["let x = v:none is v:null"], 'Cannot use "is" with special')
+ call CheckDefFailure(["let x = v:none isnot v:null"], 'Cannot use "isnot" with special')
+ call CheckDefFailure(["let x = 123 is 123"], 'Cannot use "is" with number')
+ call CheckDefFailure(["let x = 123 isnot 123"], 'Cannot use "isnot" with number')
if has('float')
- call CheckDefFailure("let x = 1.3 is 1.3", 'Cannot use "is" with float')
- call CheckDefFailure("let x = 1.3 isnot 1.3", 'Cannot use "isnot" with float')
+ call CheckDefFailure(["let x = 1.3 is 1.3"], 'Cannot use "is" with float')
+ call CheckDefFailure(["let x = 1.3 isnot 1.3"], 'Cannot use "isnot" with float')
endif
- call CheckDefFailure("let x = 0za1 > 0z34", 'Cannot compare blob with blob')
- call CheckDefFailure("let x = 0za1 >= 0z34", 'Cannot compare blob with blob')
- call CheckDefFailure("let x = 0za1 < 0z34", 'Cannot compare blob with blob')
- call CheckDefFailure("let x = 0za1 <= 0z34", 'Cannot compare blob with blob')
- call CheckDefFailure("let x = 0za1 =~ 0z34", 'Cannot compare blob with blob')
- call CheckDefFailure("let x = 0za1 !~ 0z34", 'Cannot compare blob with blob')
-
- call CheckDefFailure("let x = [13] > [88]", 'Cannot compare list with list')
- call CheckDefFailure("let x = [13] >= [88]", 'Cannot compare list with list')
- call CheckDefFailure("let x = [13] < [88]", 'Cannot compare list with list')
- call CheckDefFailure("let x = [13] <= [88]", 'Cannot compare list with list')
- call CheckDefFailure("let x = [13] =~ [88]", 'Cannot compare list with list')
- call CheckDefFailure("let x = [13] !~ [88]", 'Cannot compare list with list')
-
- call CheckDefFailureMult(['let j: job', 'let chan: channel', 'let r = j == chan'], 'Cannot compare job with channel')
- call CheckDefFailureMult(['let j: job', 'let x: list<any>', 'let r = j == x'], 'Cannot compare job with list')
- call CheckDefFailureMult(['let j: job', 'let Xx: func', 'let r = j == Xx'], 'Cannot compare job with func')
- call CheckDefFailureMult(['let j: job', 'let Xx: func', 'let r = j == Xx'], 'Cannot compare job with func')
+ call CheckDefFailure(["let x = 0za1 > 0z34"], 'Cannot compare blob with blob')
+ call CheckDefFailure(["let x = 0za1 >= 0z34"], 'Cannot compare blob with blob')
+ call CheckDefFailure(["let x = 0za1 < 0z34"], 'Cannot compare blob with blob')
+ call CheckDefFailure(["let x = 0za1 <= 0z34"], 'Cannot compare blob with blob')
+ call CheckDefFailure(["let x = 0za1 =~ 0z34"], 'Cannot compare blob with blob')
+ call CheckDefFailure(["let x = 0za1 !~ 0z34"], 'Cannot compare blob with blob')
+
+ call CheckDefFailure(["let x = [13] > [88]"], 'Cannot compare list with list')
+ call CheckDefFailure(["let x = [13] >= [88]"], 'Cannot compare list with list')
+ call CheckDefFailure(["let x = [13] < [88]"], 'Cannot compare list with list')
+ call CheckDefFailure(["let x = [13] <= [88]"], 'Cannot compare list with list')
+ call CheckDefFailure(["let x = [13] =~ [88]"], 'Cannot compare list with list')
+ call CheckDefFailure(["let x = [13] !~ [88]"], 'Cannot compare list with list')
+
+ call CheckDefFailure(['let j: job', 'let chan: channel', 'let r = j == chan'], 'Cannot compare job with channel')
+ call CheckDefFailure(['let j: job', 'let x: list<any>', 'let r = j == x'], 'Cannot compare job with list')
+ call CheckDefFailure(['let j: job', 'let Xx: func', 'let r = j == Xx'], 'Cannot compare job with func')
+ call CheckDefFailure(['let j: job', 'let Xx: func', 'let r = j == Xx'], 'Cannot compare job with func')
endfunc
" test addition, subtraction, concatenation
@@ -532,27 +506,27 @@ enddef
func Test_expr5_fails()
let msg = "white space required before and after '+'"
- call CheckDefFailure("let x = 1+2", msg)
- call CheckDefFailure("let x = 1 +2", msg)
- call CheckDefFailure("let x = 1+ 2", msg)
+ call CheckDefFailure(["let x = 1+2"], msg)
+ call CheckDefFailure(["let x = 1 +2"], msg)
+ call CheckDefFailure(["let x = 1+ 2"], msg)
let msg = "white space required before and after '-'"
- call CheckDefFailure("let x = 1-2", msg)
- call CheckDefFailure("let x = 1 -2", msg)
- call CheckDefFailure("let x = 1- 2", msg)
+ call CheckDefFailure(["let x = 1-2"], msg)
+ call CheckDefFailure(["let x = 1 -2"], msg)
+ call CheckDefFailure(["let x = 1- 2"], msg)
let msg = "white space required before and after '..'"
- call CheckDefFailure("let x = '1'..'2'", msg)
- call CheckDefFailure("let x = '1' ..'2'", msg)
- call CheckDefFailure("let x = '1'.. '2'", msg)
-
- call CheckDefFailure("let x = 0z1122 + 33", 'E1035')
- call CheckDefFailure("let x = 0z1122 + [3]", 'E1035')
- call CheckDefFailure("let x = 0z1122 + 'asd'", 'E1035')
- call CheckDefFailure("let x = 33 + 0z1122", 'E1035')
- call CheckDefFailure("let x = [3] + 0z1122", 'E1035')
- call CheckDefFailure("let x = 'asdf' + 0z1122", 'E1035')
- call CheckDefFailure("let x = 6 + xxx", 'E1001')
+ call CheckDefFailure(["let x = '1'..'2'"], msg)
+ call CheckDefFailure(["let x = '1' ..'2'"], msg)
+ call CheckDefFailure(["let x = '1'.. '2'"], msg)
+
+ call CheckDefFailure(["let x = 0z1122 + 33"], 'E1035')
+ call CheckDefFailure(["let x = 0z1122 + [3]"], 'E1035')
+ call CheckDefFailure(["let x = 0z1122 + 'asd'"], 'E1035')
+ call CheckDefFailure(["let x = 33 + 0z1122"], 'E1035')
+ call CheckDefFailure(["let x = [3] + 0z1122"], 'E1035')
+ call CheckDefFailure(["let x = 'asdf' + 0z1122"], 'E1035')
+ call CheckDefFailure(["let x = 6 + xxx"], 'E1001')
endfunc
" test multiply, divide, modulo
@@ -588,7 +562,7 @@ def Test_expr6()
assert_equal(6.0, xf[0] * yf[0])
endif
- call CheckDefFailure("let x = 6 * xxx", 'E1001')
+ call CheckDefFailure(["let x = 6 * xxx"], 'E1001')
enddef
def Test_expr6_float()
@@ -623,45 +597,45 @@ enddef
func Test_expr6_fails()
let msg = "white space required before and after '*'"
- call CheckDefFailure("let x = 1*2", msg)
- call CheckDefFailure("let x = 1 *2", msg)
- call CheckDefFailure("let x = 1* 2", msg)
+ call CheckDefFailure(["let x = 1*2"], msg)
+ call CheckDefFailure(["let x = 1 *2"], msg)
+ call CheckDefFailure(["let x = 1* 2"], msg)
let msg = "white space required before and after '/'"
- call CheckDefFailure("let x = 1/2", msg)
- call CheckDefFailure("let x = 1 /2", msg)
- call CheckDefFailure("let x = 1/ 2", msg)
+ call CheckDefFailure(["let x = 1/2"], msg)
+ call CheckDefFailure(["let x = 1 /2"], msg)
+ call CheckDefFailure(["let x = 1/ 2"], msg)
let msg = "white space required before and after '%'"
- call CheckDefFailure("let x = 1%2", msg)
- call CheckDefFailure("let x = 1 %2", msg)
- call CheckDefFailure("let x = 1% 2", msg)
+ call CheckDefFailure(["let x = 1%2"], msg)
+ call CheckDefFailure(["let x = 1 %2"], msg)
+ call CheckDefFailure(["let x = 1% 2"], msg)
- call CheckDefFailure("let x = '1' * '2'", 'E1036:')
- call CheckDefFailure("let x = '1' / '2'", 'E1036:')
- call CheckDefFailure("let x = '1' % '2'", 'E1035:')
+ call CheckDefFailure(["let x = '1' * '2'"], 'E1036:')
+ call CheckDefFailure(["let x = '1' / '2'"], 'E1036:')
+ call CheckDefFailure(["let x = '1' % '2'"], 'E1035:')
- call CheckDefFailure("let x = 0z01 * 0z12", 'E1036:')
- call CheckDefFailure("let x = 0z01 / 0z12", 'E1036:')
- call CheckDefFailure("let x = 0z01 % 0z12", 'E1035:')
+ call CheckDefFailure(["let x = 0z01 * 0z12"], 'E1036:')
+ call CheckDefFailure(["let x = 0z01 / 0z12"], 'E1036:')
+ call CheckDefFailure(["let x = 0z01 % 0z12"], 'E1035:')
- call CheckDefFailure("let x = [1] * [2]", 'E1036:')
- call CheckDefFailure("let x = [1] / [2]", 'E1036:')
- call CheckDefFailure("let x = [1] % [2]", 'E1035:')
+ call CheckDefFailure(["let x = [1] * [2]"], 'E1036:')
+ call CheckDefFailure(["let x = [1] / [2]"], 'E1036:')
+ call CheckDefFailure(["let x = [1] % [2]"], 'E1035:')
- call CheckDefFailure("let x = #{one: 1} * #{two: 2}", 'E1036:')
- call CheckDefFailure("let x = #{one: 1} / #{two: 2}", 'E1036:')
- call CheckDefFailure("let x = #{one: 1} % #{two: 2}", 'E1035:')
+ call CheckDefFailure(["let x = #{one: 1} * #{two: 2}"], 'E1036:')
+ call CheckDefFailure(["let x = #{one: 1} / #{two: 2}"], 'E1036:')
+ call CheckDefFailure(["let x = #{one: 1} % #{two: 2}"], 'E1035:')
- call CheckDefFailure("let x = 0xff[1]", 'E714:')
+ call CheckDefFailure(["let x = 0xff[1]"], 'E714:')
if has('float')
- call CheckDefFailure("let x = 0.7[1]", 'E714:')
+ call CheckDefFailure(["let x = 0.7[1]"], 'E714:')
endif
endfunc
func Test_expr6_float_fails()
CheckFeature float
- call CheckDefFailure("let x = 1.0 % 2", 'E1035:')
+ call CheckDefFailure(["let x = 1.0 % 2"], 'E1035:')
endfunc
" define here to use old style parsing
@@ -721,7 +695,7 @@ def Test_expr7_blob()
assert_equal(g:blob_one, 0z01)
assert_equal(g:blob_long, 0z0102.0304)
- call CheckDefFailure("let x = 0z123", 'E973:')
+ call CheckDefFailure(["let x = 0z123"], 'E973:')
enddef
def Test_expr7_string()
@@ -734,16 +708,16 @@ def Test_expr7_string()
assert_equal(g:string_long, "abcdefghijklm")
assert_equal(g:string_special, "ab\ncd\ref\ekk")
- call CheckDefFailure('let x = "abc', 'E114:')
- call CheckDefFailure("let x = 'abc", 'E115:')
+ call CheckDefFailure(['let x = "abc'], 'E114:')
+ call CheckDefFailure(["let x = 'abc"], 'E115:')
enddef
def Test_expr7_vimvar()
let old: list<string> = v:oldfiles
let compl: dict<any> = v:completed_item
- call CheckDefFailure("let old: list<number> = v:oldfiles", 'E1013: type mismatch, expected list<number> but got list<string>')
- call CheckDefFailure("let old: dict<number> = v:completed_item", 'E1013: type mismatch, expected dict<number> but got dict<any>')
+ call CheckDefFailure(["let old: list<number> = v:oldfiles"], 'E1013: type mismatch, expected list<number> but got list<string>')
+ call CheckDefFailure(["let old: dict<number> = v:completed_item"], 'E1013: type mismatch, expected dict<number> but got dict<any>')
enddef
def Test_expr7_special()
@@ -755,11 +729,11 @@ def Test_expr7_special()
assert_equal(g:special_null, v:null)
assert_equal(g:special_none, v:none)
- call CheckDefFailure('v:true = true', 'E46:')
- call CheckDefFailure('v:true = false', 'E46:')
- call CheckDefFailure('v:false = true', 'E46:')
- call CheckDefFailure('v:null = 11', 'E46:')
- call CheckDefFailure('v:none = 22', 'E46:')
+ call CheckDefFailure(['v:true = true'], 'E46:')
+ call CheckDefFailure(['v:true = false'], 'E46:')
+ call CheckDefFailure(['v:false = true'], 'E46:')
+ call CheckDefFailure(['v:null = 11'], 'E46:')
+ call CheckDefFailure(['v:none = 22'], 'E46:')
enddef
def Test_expr7_list()
@@ -770,9 +744,9 @@ def Test_expr7_list()
assert_equal('b', g:list_mixed[1])
call CheckDefExecFailure("let x = g:anint[3]", 'E714:')
- call CheckDefFailure("let x = g:list_mixed[xxx]", 'E1001:')
+ call CheckDefFailure(["let x = g:list_mixed[xxx]"], 'E1001:')
call CheckDefExecFailure("let x = g:list_mixed['xx']", 'E39:')
- call CheckDefFailure("let x = g:list_mixed[0", 'E111:')
+ call CheckDefFailure(["let x = g:list_mixed[0"], 'E111:')
call CheckDefExecFailure("let x = g:list_empty[3]", 'E684:')
enddef
@@ -792,16 +766,16 @@ def Test_expr7_dict()
let val = 1
assert_equal(g:dict_one, {key: val})
- call CheckDefFailure("let x = #{8: 8}", 'E1014:')
- call CheckDefFailure("let x = #{xxx}", 'E720:')
- call CheckDefFailureMult(["let x = #{xxx: 1", "let y = 2"], 'E722:')
- call CheckDefFailure("let x = #{xxx: 1,", 'E723:')
- call CheckDefFailure("let x = {'a': xxx}", 'E1001:')
- call CheckDefFailure("let x = {xxx: 8}", 'E1001:')
- call CheckDefFailure("let x = #{a: 1, a: 2}", 'E721:')
- call CheckDefFailure("let x = #", 'E1015:')
- call CheckDefFailure("let x += 1", 'E1020:')
- call CheckDefFailure("let x = x + 1", 'E1001:')
+ call CheckDefFailure(["let x = #{8: 8}"], 'E1014:')
+ call CheckDefFailure(["let x = #{xxx}"], 'E720:')
+ call CheckDefFailure(["let x = #{xxx: 1", "let y = 2"], 'E722:')
+ call CheckDefFailure(["let x = #{xxx: 1,"], 'E723:')
+ call CheckDefFailure(["let x = {'a': xxx}"], 'E1001:')
+ call CheckDefFailure(["let x = {xxx: 8}"], 'E1001:')
+ call CheckDefFailure(["let x = #{a: 1, a: 2}"], 'E721:')
+ call CheckDefFailure(["let x = #"], 'E1015:')
+ call CheckDefFailure(["let x += 1"], 'E1020:')
+ call CheckDefFailure(["let x = x + 1"], 'E1001:')
call CheckDefExecFailure("let x = g:anint.member", 'E715:')
call CheckDefExecFailure("let x = g:dict_empty.member", 'E716:')
enddef
@@ -809,7 +783,7 @@ enddef
def Test_expr_member()
assert_equal(1, g:dict_one.one)
- call CheckDefFailure("let x = g:dict_one.#$!", 'E1002:')
+ call CheckDefFailure(["let x = g:dict_one.#$!"], 'E1002:')
enddef
def Test_expr7_option()
@@ -831,7 +805,7 @@ def Test_expr7_environment()
assert_equal('testvar', $TESTVAR)
assert_equal('', $ASDF_ASD_XXX)
- call CheckDefFailure("let x = $$$", 'E1002:')
+ call CheckDefFailure(["let x = $$$"], 'E1002:')
enddef
def Test_expr7_register()
@@ -871,7 +845,7 @@ def Test_expr7_call()
assert_equal('yes', 'yes'->Echo())
assert_equal('yes', 'yes'->s:EchoArg())
- call CheckDefFailure("let x = 'yes'->Echo", 'E107:')
+ call CheckDefFailure(["let x = 'yes'->Echo"], 'E107:')
enddef
@@ -904,39 +878,39 @@ def Test_expr7_not()
enddef
func Test_expr7_fails()
- call CheckDefFailure("let x = (12", "E110:")
+ call CheckDefFailure(["let x = (12"], "E110:")
- call CheckDefFailure("let x = -'xx'", "E1030:")
- call CheckDefFailure("let x = +'xx'", "E1030:")
- call CheckDefFailure("let x = -0z12", "E974:")
+ call CheckDefFailure(["let x = -'xx'"], "E1030:")
+ call CheckDefFailure(["let x = +'xx'"], "E1030:")
+ call CheckDefFailure(["let x = -0z12"], "E974:")
call CheckDefExecFailure("let x = -[8]", "E39:")
call CheckDefExecFailure("let x = -{'a': 1}", "E39:")
- call CheckDefFailure("let x = @", "E1002:")
- call CheckDefFailure("let x = @<", "E354:")
+ call CheckDefFailure(["let x = @"], "E1002:")
+ call CheckDefFailure(["let x = @<"], "E354:")
- call CheckDefFailure("let x = [1, 2", "E697:")
- call CheckDefFailure("let x = [notfound]", "E1001:")
+ call CheckDefFailure(["let x = [1, 2"], "E697:")
+ call CheckDefFailure(["let x = [notfound]"], "E1001:")
- call CheckDefFailure("let x = { -> 123) }", "E451:")
- call CheckDefFailure("let x = 123->{x -> x + 5) }", "E451:")
+ call CheckDefFailure(["let x = { -> 123) }"], "E451:")
+ call CheckDefFailure(["let x = 123->{x -> x + 5) }"], "E451:")
- call CheckDefFailure("let x = &notexist", 'E113:')
- call CheckDefFailure("&grepprg = [343]", 'E1013:')
+ call CheckDefFailure(["let x = &notexist"], 'E113:')
+ call CheckDefFailure(["&grepprg = [343]"], 'E1013:')
call CheckDefExecFailure("echo s:doesnt_exist", 'E121:')
call CheckDefExecFailure("echo g:doesnt_exist", 'E121:')
- call CheckDefFailure("echo a:somevar", 'E1075:')
- call CheckDefFailure("echo l:somevar", 'E1075:')
- call CheckDefFailure("echo x:somevar", 'E1075:')
+ call CheckDefFailure(["echo a:somevar"], 'E1075:')
+ call CheckDefFailure(["echo l:somevar"], 'E1075:')
+ call CheckDefFailure(["echo x:somevar"], 'E1075:')
call CheckDefExecFailure("let x = +g:astring", 'E1030:')
call CheckDefExecFailure("let x = +g:ablob", 'E974:')
call CheckDefExecFailure("let x = +g:alist", 'E745:')
call CheckDefExecFailure("let x = +g:adict", 'E728:')
- call CheckDefFailureMult(["let x = ''", "let y = x.memb"], 'E715:')
+ call CheckDefFailure(["let x = ''", "let y = x.memb"], 'E715:')
call CheckDefExecFailure("[1, 2->len()", 'E492:')
call CheckDefExecFailure("#{a: 1->len()", 'E488:')
@@ -988,23 +962,23 @@ enddef
func Test_expr7_trailing_fails()
- call CheckDefFailureList(['let l = [2]', 'l->{l -> add(l, 8)}'], 'E107')
- call CheckDefFailureList(['let l = [2]', 'l->{l -> add(l, 8)} ()'], 'E274')
+ call CheckDefFailure(['let l = [2]', 'l->{l -> add(l, 8)}'], 'E107')
+ call CheckDefFailure(['let l = [2]', 'l->{l -> add(l, 8)} ()'], 'E274')
endfunc
func Test_expr_fails()
- call CheckDefFailure("let x = '1'is2", 'E488:')
- call CheckDefFailure("let x = '1'isnot2", 'E488:')
+ call CheckDefFailure(["let x = '1'is2"], 'E488:')
+ call CheckDefFailure(["let x = '1'isnot2"], 'E488:')
call CheckDefExecFailure("CallMe ('yes')", 'E492:')
- call CheckDefFailure("CallMe2('yes','no')", 'E1069:')
- call CheckDefFailure("CallMe2('yes' , 'no')", 'E1068:')
+ call CheckDefFailure(["CallMe2('yes','no')"], 'E1069:')
+ call CheckDefFailure(["CallMe2('yes' , 'no')"], 'E1068:')
- call CheckDefFailure("v:nosuch += 3", 'E1001:')
- call CheckDefFailure("let v:statusmsg = ''", 'E1064:')
- call CheckDefFailure("let asdf = v:nosuch", 'E1001:')
+ call CheckDefFailure(["v:nosuch += 3"], 'E1001:')
+ call CheckDefFailure(["let v:statusmsg = ''"], 'E1064:')
+ call CheckDefFailure(["let asdf = v:nosuch"], 'E1001:')
- call CheckDefFailure("echo len('asdf'", 'E110:')
- call CheckDefFailure("echo Func0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789()", 'E1011:')
- call CheckDefFailure("echo doesnotexist()", 'E117:')
+ call CheckDefFailure(["echo len('asdf'"], 'E110:')
+ call CheckDefFailure(["echo Func0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789()"], 'E1011:')
+ call CheckDefFailure(["echo doesnotexist()"], 'E117:')
endfunc
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index f06bb734c..218ef7740 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -2,25 +2,7 @@
source check.vim
source view_util.vim
-
-" Check that "lines" inside ":def" results in an "error" message.
-func CheckDefFailure(lines, error)
- call writefile(['def Func()'] + a:lines + ['enddef'], 'Xdef')
- call assert_fails('so Xdef', a:error, a:lines)
- call delete('Xdef')
-endfunc
-
-def CheckScriptFailure(lines: list<string>, error: string)
- writefile(lines, 'Xdef')
- assert_fails('so Xdef', error, lines)
- delete('Xdef')
-enddef
-
-def CheckScriptSuccess(lines: list<string>)
- writefile(lines, 'Xdef')
- so Xdef
- delete('Xdef')
-enddef
+source vim9.vim
def Test_syntax()
let var = 234
diff --git a/src/testdir/vim9.vim b/src/testdir/vim9.vim
new file mode 100644
index 000000000..0e0cd1e1f
--- /dev/null
+++ b/src/testdir/vim9.vim
@@ -0,0 +1,28 @@
+" Utility functions for testing vim9 script
+
+" Check that "lines" inside ":def" results in an "error" message.
+func CheckDefFailure(lines, error)
+ call writefile(['def Func()'] + a:lines + ['enddef'], 'Xdef')
+ call assert_fails('so Xdef', a:error, a:lines)
+ call delete('Xdef')
+endfunc
+
+def CheckScriptFailure(lines: list<string>, error: string)
+ writefile(lines, 'Xdef')
+ assert_fails('so Xdef', error, lines)
+ delete('Xdef')
+enddef
+
+def CheckScriptSuccess(lines: list<string>)
+ writefile(lines, 'Xdef')
+ so Xdef
+ delete('Xdef')
+enddef
+
+" Check that "line" inside ":def" results in an "error" message when executed.
+func CheckDefExecFailure(line, error)
+ call writefile(['def! Func()', a:line, 'enddef'], 'Xdef')
+ so Xdef
+ call assert_fails('call Func()', a:error, a:line)
+ call delete('Xdef')
+endfunc
diff --git a/src/version.c b/src/version.c
index 70af7b043..233106b24 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 640,
+/**/
639,
/**/
638,
diff --git a/src/vim9.h b/src/vim9.h
index f1da32318..ddc84b1e7 100644
--- a/src/vim9.h
+++ b/src/vim9.h
@@ -13,6 +13,7 @@
typedef enum {
ISN_EXEC, // execute Ex command line isn_arg.string
+ ISN_EXECCONCAT, // execute Ex command from isn_arg.number items on stack
ISN_ECHO, // echo isn_arg.echo.echo_count items on top of stack
ISN_EXECUTE, // execute Ex commands isn_arg.number items on top of stack
ISN_ECHOMSG, // echo Ex commands isn_arg.number items on top of stack
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 4d1e3acc6..092939e08 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1427,6 +1427,17 @@ generate_EXEC(cctx_T *cctx, char_u *line)
return OK;
}
+ static int
+generate_EXECCONCAT(cctx_T *cctx, int count)
+{
+ isn_T *isn;
+
+ if ((isn = generate_instr_drop(cctx, ISN_EXECCONCAT, count)) == NULL)
+ return FAIL;
+ isn->isn_arg.number = count;
+ return OK;
+}
+
/*
* Reserve space for a local variable.
* Return the index or -1 if it failed.
@@ -5805,6 +5816,71 @@ compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
}
/*
+ * A command that is not compiled, execute with legacy code.
+ */
+ static char_u *
+compile_exec(char_u *line, exarg_T *eap, cctx_T *cctx)
+{
+ char_u *p;
+
+ if (cctx->ctx_skip == TRUE)
+ goto theend;
+
+
+ if ((excmd_get_argt(eap->cmdidx) & EX_XFILE)
+ && (p = (char_u *)strstr((char *)eap->arg, "`=")) != NULL)
+ {
+ int count = 0;
+ char_u *start = skipwhite(line);
+
+ // :cmd xxx`=expr1`yyy`=expr2`zzz
+ // PUSHS ":cmd xxx"
+ // eval expr1
+ // PUSHS "yyy"
+ // eval expr2
+ // PUSHS "zzz"
+ // EXECCONCAT 5
+ for (;;)
+ {
+ if (p > start)
+ {
+ generate_PUSHS(cctx, vim_strnsave(start, (int)(p - start)));
+ ++count;
+ }
+ p += 2;
+ if (compile_expr1(&p, cctx) == FAIL)
+ return NULL;
+ may_generate_2STRING(-1, cctx);
+ ++count;
+ p = skipwhite(p);
+ if (*p != '`')
+ {
+ emsg(_("E1083: missing backtick"));
+ return NULL;
+ }
+ start = p + 1;
+
+ p = (char_u *)strstr((char *)start, "`=");
+ if (p == NULL)
+ {
+ if (*skipwhite(start) != NUL)
+ {
+ generate_PUSHS(cctx, vim_strsave(start));
+ ++count;
+ }
+ break;
+ }
+ }
+ generate_EXECCONCAT(cctx, count);
+ }
+ else
+ generate_EXEC(cctx, line);
+
+theend:
+ return (char_u *)"";
+}
+
+/*
* After ex_function() has collected all the function lines: parse and compile
* the lines into instructions.
* Adds the function to "def_functions".
@@ -5818,7 +5894,6 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
{
char_u *line = NULL;
char_u *p;
- exarg_T ea;
char *errormsg = NULL; // error message
int had_return = FALSE;
cctx_T cctx;
@@ -5917,6 +5992,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
*/
for (;;)
{
+ exarg_T ea;
int is_ex_command = FALSE;
// Bail out on the first error to avoid a flood of errors and report
@@ -5952,7 +6028,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
switch (*ea.cmd)
{
case '#':
- // "#" starts a comment, but not "#{".
+ // "#" starts a comment, but "#{" does not.
if (ea.cmd[1] != '{')
{
line = (char_u *)"";
@@ -6093,7 +6169,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
&& ea.cmdidx != CMD_else
&& ea.cmdidx != CMD_endif)
{
- line += STRLEN(line);
+ line = (char_u *)"";
continue;
}
@@ -6183,10 +6259,10 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
break;
default:
- // Not recognized, execute with do_cmdline_cmd().
// TODO: other commands with an expression argument
- generate_EXEC(&cctx, line);
- line = (char_u *)"";
+ // Not recognized, execute with do_cmdline_cmd().
+ ea.arg = p;
+ line = compile_exec(line, &ea, &cctx);
break;
}
if (line == NULL)
@@ -6401,10 +6477,11 @@ delete_instr(isn_T *isn)
case ISN_DCALL:
case ISN_DROP:
case ISN_ECHO:
- case ISN_EXECUTE:
- case ISN_ECHOMSG:
case ISN_ECHOERR:
+ case ISN_ECHOMSG:
case ISN_ENDTRY:
+ case ISN_EXECCONCAT:
+ case ISN_EXECUTE:
case ISN_FOR:
case ISN_FUNCREF:
case ISN_INDEX:
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 8c136967f..7172718c2 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -648,6 +648,45 @@ call_def_function(
do_cmdline_cmd(iptr->isn_arg.string);
break;
+ // execute Ex command from pieces on the stack
+ case ISN_EXECCONCAT:
+ {
+ int count = iptr->isn_arg.number;
+ int len = 0;
+ int pass;
+ int i;
+ char_u *cmd = NULL;
+ char_u *str;
+
+ for (pass = 1; pass <= 2; ++pass)
+ {
+ for (i = 0; i < count; ++i)
+ {
+ tv = STACK_TV_BOT(i - count);
+ str = tv->vval.v_string;
+ if (str != NULL && *str != NUL)
+ {
+ if (pass == 2)
+ STRCPY(cmd + len, str);
+ len += STRLEN(str);
+ }
+ if (pass == 2)
+ clear_tv(tv);
+ }
+ if (pass == 1)
+ {
+ cmd = alloc(len + 1);
+ if (cmd == NULL)
+ goto failed;
+ len = 0;
+ }
+ }
+
+ do_cmdline_cmd(cmd);
+ vim_free(cmd);
+ }
+ break;
+
// execute :echo {string} ...
case ISN_ECHO:
{
@@ -1961,6 +2000,10 @@ ex_disassemble(exarg_T *eap)
case ISN_EXEC:
smsg("%4d EXEC %s", current, iptr->isn_arg.string);
break;
+ case ISN_EXECCONCAT:
+ smsg("%4d EXECCONCAT %lld", current,
+ (long long)iptr->isn_arg.number);
+ break;
case ISN_ECHO:
{
echo_T *echo = &iptr->isn_arg.echo;