0
0
mirror of https://github.com/vim/vim.git synced 2025-10-03 05:14:07 -04:00

patch 8.2.0640: Vim9: expanding does not work

Problem:    Vim9: expanding  does not work.
Solution:   Find wildcards in not compiled commands.  Reorganize test files.
This commit is contained in:
Bram Moolenaar
2020-04-25 20:02:55 +02:00
parent 49b2fb36ca
commit cfe435d7fe
11 changed files with 373 additions and 214 deletions

View File

@@ -162,6 +162,7 @@ SRC_ALL = \
src/testdir/setup.vim \ src/testdir/setup.vim \
src/testdir/setup_gui.vim \ src/testdir/setup_gui.vim \
src/testdir/shared.vim \ src/testdir/shared.vim \
src/testdir/vim9.vim \
src/testdir/summarize.vim \ src/testdir/summarize.vim \
src/testdir/term_util.vim \ src/testdir/term_util.vim \
src/testdir/view_util.vim \ src/testdir/view_util.vim \

View File

@@ -45,12 +45,14 @@ SCRIPTS_GUI =
# Tests for Vim9 script. # Tests for Vim9 script.
TEST_VIM9 = \ TEST_VIM9 = \
test_vim9_cmd \
test_vim9_disassemble \ test_vim9_disassemble \
test_vim9_expr \ test_vim9_expr \
test_vim9_func \ test_vim9_func \
test_vim9_script test_vim9_script
TEST_VIM9_RES = \ TEST_VIM9_RES = \
test_vim9_cmd.res \
test_vim9_disassemble.res \ test_vim9_disassemble.res \
test_vim9_expr.res \ test_vim9_expr.res \
test_vim9_func.res \ test_vim9_func.res \

View File

@@ -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

View File

@@ -53,6 +53,32 @@ def Test_disassemble_load()
res) res)
enddef 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() def s:ScriptFuncPush()
let localbool = true let localbool = true
let localspec = v:none let localspec = v:none

View File

@@ -1,33 +1,7 @@
" Tests for Vim9 script expressions " Tests for Vim9 script expressions
source check.vim source check.vim
source vim9.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
" test cond ? expr : expr " test cond ? expr : expr
def Test_expr1() def Test_expr1()
@@ -59,18 +33,18 @@ def Test_expr1()
enddef enddef
func Test_expr1_fails() func Test_expr1_fails()
call CheckDefFailure("let x = 1 ? 'one'", "Missing ':' after '?'") call CheckDefFailure(["let x = 1 ? 'one'"], "Missing ':' after '?'")
call CheckDefFailure("let x = 1 ? 'one' : xxx", "E1001:") call CheckDefFailure(["let x = 1 ? 'one' : xxx"], "E1001:")
let msg = "white space required before and after '?'" 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 ':'" 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 endfunc
" TODO: define inside test function " TODO: define inside test function
@@ -107,11 +81,11 @@ enddef
func Test_expr2_fails() func Test_expr2_fails()
let msg = "white space required before and after '||'" 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 endfunc
" test && " test &&
@@ -148,9 +122,9 @@ enddef
func Test_expr3_fails() func Test_expr3_fails()
let msg = "white space required before and after '&&'" 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 endfunc
let atrue = v:true let atrue = v:true
@@ -212,7 +186,7 @@ def Test_expr4_equal()
assert_equal(false, 'abc' ==# 'ABC') assert_equal(false, 'abc' ==# 'ABC')
set noignorecase set noignorecase
call CheckDefFailure("let x = 'a' == xxx", 'E1001:') call CheckDefFailure(["let x = 'a' == xxx"], 'E1001:')
assert_equal(true, 0z3f == 0z3f) assert_equal(true, 0z3f == 0z3f)
assert_equal(false, 0z3f == 0z4f) assert_equal(false, 0z3f == 0z4f)
@@ -413,71 +387,71 @@ enddef
func Test_expr4_fails() func Test_expr4_fails()
let msg = "white space required before and after '>'" 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 '=='" 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'" 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'" 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' 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 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 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 number with string')
call CheckDefFailure("let x = '1' == 2", 'Cannot compare string with number') 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 = 1 == RetVoid()"], 'Cannot use void value')
call CheckDefFailure("let x = RetVoid() == 1", 'Cannot compare void with number') 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 <= 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 is false"], 'Cannot use "is" with bool')
call CheckDefFailure("let x = true isnot false", 'Cannot use "isnot" 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 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 = 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 is 123"], 'Cannot use "is" with number')
call CheckDefFailure("let x = 123 isnot 123", 'Cannot use "isnot" with number') call CheckDefFailure(["let x = 123 isnot 123"], 'Cannot use "isnot" with number')
if has('float') if has('float')
call CheckDefFailure("let x = 1.3 is 1.3", 'Cannot use "is" 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') call CheckDefFailure(["let x = 1.3 isnot 1.3"], 'Cannot use "isnot" with float')
endif 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 = 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 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 CheckDefFailure(['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 CheckDefFailure(['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 CheckDefFailure(['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 j: job', 'let Xx: func', 'let r = j == Xx'], 'Cannot compare job with func')
endfunc endfunc
" test addition, subtraction, concatenation " test addition, subtraction, concatenation
@@ -532,27 +506,27 @@ enddef
func Test_expr5_fails() func Test_expr5_fails()
let msg = "white space required before and after '+'" 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 '-'" 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 '..'" 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 = 0z1122 + 33", 'E1035') call CheckDefFailure(["let x = 0z1122 + 33"], 'E1035')
call CheckDefFailure("let x = 0z1122 + [3]", 'E1035') call CheckDefFailure(["let x = 0z1122 + [3]"], 'E1035')
call CheckDefFailure("let x = 0z1122 + 'asd'", 'E1035') call CheckDefFailure(["let x = 0z1122 + 'asd'"], 'E1035')
call CheckDefFailure("let x = 33 + 0z1122", 'E1035') call CheckDefFailure(["let x = 33 + 0z1122"], 'E1035')
call CheckDefFailure("let x = [3] + 0z1122", 'E1035') call CheckDefFailure(["let x = [3] + 0z1122"], 'E1035')
call CheckDefFailure("let x = 'asdf' + 0z1122", 'E1035') call CheckDefFailure(["let x = 'asdf' + 0z1122"], 'E1035')
call CheckDefFailure("let x = 6 + xxx", 'E1001') call CheckDefFailure(["let x = 6 + xxx"], 'E1001')
endfunc endfunc
" test multiply, divide, modulo " test multiply, divide, modulo
@@ -588,7 +562,7 @@ def Test_expr6()
assert_equal(6.0, xf[0] * yf[0]) assert_equal(6.0, xf[0] * yf[0])
endif endif
call CheckDefFailure("let x = 6 * xxx", 'E1001') call CheckDefFailure(["let x = 6 * xxx"], 'E1001')
enddef enddef
def Test_expr6_float() def Test_expr6_float()
@@ -623,45 +597,45 @@ enddef
func Test_expr6_fails() func Test_expr6_fails()
let msg = "white space required before and after '*'" 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 '/'" 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 '%'" 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'", 'E1036:') call CheckDefFailure(["let x = '1' / '2'"], 'E1036:')
call CheckDefFailure("let x = '1' % '2'", 'E1035:') 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", 'E1036:') call CheckDefFailure(["let x = 0z01 / 0z12"], 'E1036:')
call CheckDefFailure("let x = 0z01 % 0z12", 'E1035:') 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]", 'E1036:') call CheckDefFailure(["let x = [1] / [2]"], 'E1036:')
call CheckDefFailure("let x = [1] % [2]", 'E1035:') 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}", '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}"], 'E1035:')
call CheckDefFailure("let x = 0xff[1]", 'E714:') call CheckDefFailure(["let x = 0xff[1]"], 'E714:')
if has('float') if has('float')
call CheckDefFailure("let x = 0.7[1]", 'E714:') call CheckDefFailure(["let x = 0.7[1]"], 'E714:')
endif endif
endfunc endfunc
func Test_expr6_float_fails() func Test_expr6_float_fails()
CheckFeature float CheckFeature float
call CheckDefFailure("let x = 1.0 % 2", 'E1035:') call CheckDefFailure(["let x = 1.0 % 2"], 'E1035:')
endfunc endfunc
" define here to use old style parsing " 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_one, 0z01)
assert_equal(g:blob_long, 0z0102.0304) assert_equal(g:blob_long, 0z0102.0304)
call CheckDefFailure("let x = 0z123", 'E973:') call CheckDefFailure(["let x = 0z123"], 'E973:')
enddef enddef
def Test_expr7_string() def Test_expr7_string()
@@ -734,16 +708,16 @@ def Test_expr7_string()
assert_equal(g:string_long, "abcdefghijklm") assert_equal(g:string_long, "abcdefghijklm")
assert_equal(g:string_special, "ab\ncd\ref\ekk") assert_equal(g:string_special, "ab\ncd\ref\ekk")
call CheckDefFailure('let x = "abc', 'E114:') call CheckDefFailure(['let x = "abc'], 'E114:')
call CheckDefFailure("let x = 'abc", 'E115:') call CheckDefFailure(["let x = 'abc"], 'E115:')
enddef enddef
def Test_expr7_vimvar() def Test_expr7_vimvar()
let old: list<string> = v:oldfiles let old: list<string> = v:oldfiles
let compl: dict<any> = v:completed_item 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: 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: dict<number> = v:completed_item"], 'E1013: type mismatch, expected dict<number> but got dict<any>')
enddef enddef
def Test_expr7_special() def Test_expr7_special()
@@ -755,11 +729,11 @@ def Test_expr7_special()
assert_equal(g:special_null, v:null) assert_equal(g:special_null, v:null)
assert_equal(g:special_none, v:none) assert_equal(g:special_none, v:none)
call CheckDefFailure('v:true = true', 'E46:') call CheckDefFailure(['v:true = true'], 'E46:')
call CheckDefFailure('v:true = false', 'E46:') call CheckDefFailure(['v:true = false'], 'E46:')
call CheckDefFailure('v:false = true', 'E46:') call CheckDefFailure(['v:false = true'], 'E46:')
call CheckDefFailure('v:null = 11', 'E46:') call CheckDefFailure(['v:null = 11'], 'E46:')
call CheckDefFailure('v:none = 22', 'E46:') call CheckDefFailure(['v:none = 22'], 'E46:')
enddef enddef
def Test_expr7_list() def Test_expr7_list()
@@ -770,9 +744,9 @@ def Test_expr7_list()
assert_equal('b', g:list_mixed[1]) assert_equal('b', g:list_mixed[1])
call CheckDefExecFailure("let x = g:anint[3]", 'E714:') 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 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:') call CheckDefExecFailure("let x = g:list_empty[3]", 'E684:')
enddef enddef
@@ -792,16 +766,16 @@ def Test_expr7_dict()
let val = 1 let val = 1
assert_equal(g:dict_one, {key: val}) assert_equal(g:dict_one, {key: val})
call CheckDefFailure("let x = #{8: 8}", 'E1014:') call CheckDefFailure(["let x = #{8: 8}"], 'E1014:')
call CheckDefFailure("let x = #{xxx}", 'E720:') call CheckDefFailure(["let x = #{xxx}"], 'E720:')
call CheckDefFailureMult(["let x = #{xxx: 1", "let y = 2"], 'E722:') call CheckDefFailure(["let x = #{xxx: 1", "let y = 2"], 'E722:')
call CheckDefFailure("let x = #{xxx: 1,", 'E723:') call CheckDefFailure(["let x = #{xxx: 1,"], 'E723:')
call CheckDefFailure("let x = {'a': xxx}", 'E1001:') call CheckDefFailure(["let x = {'a': xxx}"], 'E1001:')
call CheckDefFailure("let x = {xxx: 8}", 'E1001:') call CheckDefFailure(["let x = {xxx: 8}"], 'E1001:')
call CheckDefFailure("let x = #{a: 1, a: 2}", 'E721:') call CheckDefFailure(["let x = #{a: 1, a: 2}"], 'E721:')
call CheckDefFailure("let x = #", 'E1015:') call CheckDefFailure(["let x = #"], 'E1015:')
call CheckDefFailure("let x += 1", 'E1020:') call CheckDefFailure(["let x += 1"], 'E1020:')
call CheckDefFailure("let x = x + 1", 'E1001:') call CheckDefFailure(["let x = x + 1"], 'E1001:')
call CheckDefExecFailure("let x = g:anint.member", 'E715:') call CheckDefExecFailure("let x = g:anint.member", 'E715:')
call CheckDefExecFailure("let x = g:dict_empty.member", 'E716:') call CheckDefExecFailure("let x = g:dict_empty.member", 'E716:')
enddef enddef
@@ -809,7 +783,7 @@ enddef
def Test_expr_member() def Test_expr_member()
assert_equal(1, g:dict_one.one) assert_equal(1, g:dict_one.one)
call CheckDefFailure("let x = g:dict_one.#$!", 'E1002:') call CheckDefFailure(["let x = g:dict_one.#$!"], 'E1002:')
enddef enddef
def Test_expr7_option() def Test_expr7_option()
@@ -831,7 +805,7 @@ def Test_expr7_environment()
assert_equal('testvar', $TESTVAR) assert_equal('testvar', $TESTVAR)
assert_equal('', $ASDF_ASD_XXX) assert_equal('', $ASDF_ASD_XXX)
call CheckDefFailure("let x = $$$", 'E1002:') call CheckDefFailure(["let x = $$$"], 'E1002:')
enddef enddef
def Test_expr7_register() def Test_expr7_register()
@@ -871,7 +845,7 @@ def Test_expr7_call()
assert_equal('yes', 'yes'->Echo()) assert_equal('yes', 'yes'->Echo())
assert_equal('yes', 'yes'->s:EchoArg()) assert_equal('yes', 'yes'->s:EchoArg())
call CheckDefFailure("let x = 'yes'->Echo", 'E107:') call CheckDefFailure(["let x = 'yes'->Echo"], 'E107:')
enddef enddef
@@ -904,39 +878,39 @@ def Test_expr7_not()
enddef enddef
func Test_expr7_fails() 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 = +'xx'", "E1030:") call CheckDefFailure(["let x = +'xx'"], "E1030:")
call CheckDefFailure("let x = -0z12", "E974:") call CheckDefFailure(["let x = -0z12"], "E974:")
call CheckDefExecFailure("let x = -[8]", "E39:") call CheckDefExecFailure("let x = -[8]", "E39:")
call CheckDefExecFailure("let x = -{'a': 1}", "E39:") call CheckDefExecFailure("let x = -{'a': 1}", "E39:")
call CheckDefFailure("let x = @", "E1002:") call CheckDefFailure(["let x = @"], "E1002:")
call CheckDefFailure("let x = @<", "E354:") call CheckDefFailure(["let x = @<"], "E354:")
call CheckDefFailure("let x = [1, 2", "E697:") call CheckDefFailure(["let x = [1, 2"], "E697:")
call CheckDefFailure("let x = [notfound]", "E1001:") call CheckDefFailure(["let x = [notfound]"], "E1001:")
call CheckDefFailure("let x = { -> 123) }", "E451:") call CheckDefFailure(["let x = { -> 123) }"], "E451:")
call CheckDefFailure("let x = 123->{x -> x + 5) }", "E451:") call CheckDefFailure(["let x = 123->{x -> x + 5) }"], "E451:")
call CheckDefFailure("let x = &notexist", 'E113:') call CheckDefFailure(["let x = &notexist"], 'E113:')
call CheckDefFailure("&grepprg = [343]", 'E1013:') call CheckDefFailure(["&grepprg = [343]"], 'E1013:')
call CheckDefExecFailure("echo s:doesnt_exist", 'E121:') call CheckDefExecFailure("echo s:doesnt_exist", 'E121:')
call CheckDefExecFailure("echo g:doesnt_exist", 'E121:') call CheckDefExecFailure("echo g:doesnt_exist", 'E121:')
call CheckDefFailure("echo a:somevar", 'E1075:') call CheckDefFailure(["echo a:somevar"], 'E1075:')
call CheckDefFailure("echo l:somevar", 'E1075:') call CheckDefFailure(["echo l:somevar"], 'E1075:')
call CheckDefFailure("echo x:somevar", 'E1075:') call CheckDefFailure(["echo x:somevar"], 'E1075:')
call CheckDefExecFailure("let x = +g:astring", 'E1030:') call CheckDefExecFailure("let x = +g:astring", 'E1030:')
call CheckDefExecFailure("let x = +g:ablob", 'E974:') call CheckDefExecFailure("let x = +g:ablob", 'E974:')
call CheckDefExecFailure("let x = +g:alist", 'E745:') call CheckDefExecFailure("let x = +g:alist", 'E745:')
call CheckDefExecFailure("let x = +g:adict", 'E728:') 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("[1, 2->len()", 'E492:')
call CheckDefExecFailure("#{a: 1->len()", 'E488:') call CheckDefExecFailure("#{a: 1->len()", 'E488:')
@@ -988,23 +962,23 @@ enddef
func Test_expr7_trailing_fails() func Test_expr7_trailing_fails()
call CheckDefFailureList(['let l = [2]', 'l->{l -> add(l, 8)}'], 'E107') call CheckDefFailure(['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)} ()'], 'E274')
endfunc endfunc
func Test_expr_fails() func Test_expr_fails()
call CheckDefFailure("let x = '1'is2", 'E488:') call CheckDefFailure(["let x = '1'is2"], 'E488:')
call CheckDefFailure("let x = '1'isnot2", 'E488:') call CheckDefFailure(["let x = '1'isnot2"], 'E488:')
call CheckDefExecFailure("CallMe ('yes')", 'E492:') call CheckDefExecFailure("CallMe ('yes')", 'E492:')
call CheckDefFailure("CallMe2('yes','no')", 'E1069:') call CheckDefFailure(["CallMe2('yes','no')"], 'E1069:')
call CheckDefFailure("CallMe2('yes' , 'no')", 'E1068:') call CheckDefFailure(["CallMe2('yes' , 'no')"], 'E1068:')
call CheckDefFailure("v:nosuch += 3", 'E1001:') call CheckDefFailure(["v:nosuch += 3"], 'E1001:')
call CheckDefFailure("let v:statusmsg = ''", 'E1064:') call CheckDefFailure(["let v:statusmsg = ''"], 'E1064:')
call CheckDefFailure("let asdf = v:nosuch", 'E1001:') call CheckDefFailure(["let asdf = v:nosuch"], 'E1001:')
call CheckDefFailure("echo len('asdf'", 'E110:') call CheckDefFailure(["echo len('asdf'"], 'E110:')
call CheckDefFailure("echo Func0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789()", 'E1011:') call CheckDefFailure(["echo Func0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789()"], 'E1011:')
call CheckDefFailure("echo doesnotexist()", 'E117:') call CheckDefFailure(["echo doesnotexist()"], 'E117:')
endfunc endfunc

View File

@@ -2,25 +2,7 @@
source check.vim source check.vim
source view_util.vim source view_util.vim
source vim9.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
def Test_syntax() def Test_syntax()
let var = 234 let var = 234

28
src/testdir/vim9.vim Normal file
View File

@@ -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

View File

@@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
640,
/**/ /**/
639, 639,
/**/ /**/

View File

@@ -13,6 +13,7 @@
typedef enum { typedef enum {
ISN_EXEC, // execute Ex command line isn_arg.string 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_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_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 ISN_ECHOMSG, // echo Ex commands isn_arg.number items on top of stack

View File

@@ -1427,6 +1427,17 @@ generate_EXEC(cctx_T *cctx, char_u *line)
return OK; 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. * Reserve space for a local variable.
* Return the index or -1 if it failed. * Return the index or -1 if it failed.
@@ -5804,6 +5815,71 @@ compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
return p; return p;
} }
/*
* 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 * After ex_function() has collected all the function lines: parse and compile
* the lines into instructions. * the lines into instructions.
@@ -5818,7 +5894,6 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
{ {
char_u *line = NULL; char_u *line = NULL;
char_u *p; char_u *p;
exarg_T ea;
char *errormsg = NULL; // error message char *errormsg = NULL; // error message
int had_return = FALSE; int had_return = FALSE;
cctx_T cctx; cctx_T cctx;
@@ -5917,6 +5992,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
*/ */
for (;;) for (;;)
{ {
exarg_T ea;
int is_ex_command = FALSE; int is_ex_command = FALSE;
// Bail out on the first error to avoid a flood of errors and report // 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) switch (*ea.cmd)
{ {
case '#': case '#':
// "#" starts a comment, but not "#{". // "#" starts a comment, but "#{" does not.
if (ea.cmd[1] != '{') if (ea.cmd[1] != '{')
{ {
line = (char_u *)""; line = (char_u *)"";
@@ -6093,7 +6169,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
&& ea.cmdidx != CMD_else && ea.cmdidx != CMD_else
&& ea.cmdidx != CMD_endif) && ea.cmdidx != CMD_endif)
{ {
line += STRLEN(line); line = (char_u *)"";
continue; continue;
} }
@@ -6183,10 +6259,10 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
break; break;
default: default:
// Not recognized, execute with do_cmdline_cmd().
// TODO: other commands with an expression argument // TODO: other commands with an expression argument
generate_EXEC(&cctx, line); // Not recognized, execute with do_cmdline_cmd().
line = (char_u *)""; ea.arg = p;
line = compile_exec(line, &ea, &cctx);
break; break;
} }
if (line == NULL) if (line == NULL)
@@ -6401,10 +6477,11 @@ delete_instr(isn_T *isn)
case ISN_DCALL: case ISN_DCALL:
case ISN_DROP: case ISN_DROP:
case ISN_ECHO: case ISN_ECHO:
case ISN_EXECUTE:
case ISN_ECHOMSG:
case ISN_ECHOERR: case ISN_ECHOERR:
case ISN_ECHOMSG:
case ISN_ENDTRY: case ISN_ENDTRY:
case ISN_EXECCONCAT:
case ISN_EXECUTE:
case ISN_FOR: case ISN_FOR:
case ISN_FUNCREF: case ISN_FUNCREF:
case ISN_INDEX: case ISN_INDEX:

View File

@@ -648,6 +648,45 @@ call_def_function(
do_cmdline_cmd(iptr->isn_arg.string); do_cmdline_cmd(iptr->isn_arg.string);
break; 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} ... // execute :echo {string} ...
case ISN_ECHO: case ISN_ECHO:
{ {
@@ -1961,6 +2000,10 @@ ex_disassemble(exarg_T *eap)
case ISN_EXEC: case ISN_EXEC:
smsg("%4d EXEC %s", current, iptr->isn_arg.string); smsg("%4d EXEC %s", current, iptr->isn_arg.string);
break; break;
case ISN_EXECCONCAT:
smsg("%4d EXECCONCAT %lld", current,
(long long)iptr->isn_arg.number);
break;
case ISN_ECHO: case ISN_ECHO:
{ {
echo_T *echo = &iptr->isn_arg.echo; echo_T *echo = &iptr->isn_arg.echo;