Mercurial > vim
diff src/testdir/test_vim9_disassemble.vim @ 21833:e3f9528bddda v8.2.1466
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Commit: https://github.com/vim/vim/commit/cc673e746ab98566556ff964d7a76f2fb46d7f84
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 16 17:33:35 2020 +0200
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Problem: Vim9: cannot index or slice a variable with type "any".
Solution: Add runtime index and slice.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 16 Aug 2020 17:45:22 +0200 |
parents | af5db9b6d210 |
children | d55008685870 |
line wrap: on
line diff
--- a/src/testdir/test_vim9_disassemble.vim +++ b/src/testdir/test_vim9_disassemble.vim @@ -1091,6 +1091,50 @@ def Test_disassemble_dict_member() call assert_equal(1, DictMember()) enddef +let somelist = [1, 2, 3, 4, 5] +def AnyIndex(): number + let res = g:somelist[2] + return res +enddef + +def Test_disassemble_any_index() + let instr = execute('disassemble AnyIndex') + assert_match('AnyIndex\_s*' .. + 'let res = g:somelist\[2\]\_s*' .. + '\d LOADG g:somelist\_s*' .. + '\d PUSHNR 2\_s*' .. + '\d ANYINDEX\_s*' .. + '\d STORE $0\_s*' .. + 'return res\_s*' .. + '\d LOAD $0\_s*' .. + '\d CHECKTYPE number stack\[-1\]\_s*' .. + '\d RETURN', + instr) + assert_equal(3, AnyIndex()) +enddef + +def AnySlice(): list<number> + let res = g:somelist[1:3] + return res +enddef + +def Test_disassemble_any_slice() + let instr = execute('disassemble AnySlice') + assert_match('AnySlice\_s*' .. + 'let res = g:somelist\[1:3\]\_s*' .. + '\d LOADG g:somelist\_s*' .. + '\d PUSHNR 1\_s*' .. + '\d PUSHNR 3\_s*' .. + '\d ANYSLICE\_s*' .. + '\d STORE $0\_s*' .. + 'return res\_s*' .. + '\d LOAD $0\_s*' .. + '\d CHECKTYPE list stack\[-1\]\_s*' .. + '\d RETURN', + instr) + assert_equal([2, 3, 4], AnySlice()) +enddef + def NegateNumber(): number let nr = 9 let plus = +nr