diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:05:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:05:19 +0000 |
commit | a4e9136f68a40b1cb0eb6df5a5f06603224a87f4 (patch) | |
tree | ba32e0d0069ad6adfd6b32d05161a03eea5e4c7c /src/testdir/test_vim9_disassemble.vim | |
parent | Releasing progress-linux version 2:9.1.0496-1~progress7.99u1. (diff) | |
download | vim-a4e9136f68a40b1cb0eb6df5a5f06603224a87f4.tar.xz vim-a4e9136f68a40b1cb0eb6df5a5f06603224a87f4.zip |
Merging upstream version 2:9.1.0698.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/testdir/test_vim9_disassemble.vim')
-rw-r--r-- | src/testdir/test_vim9_disassemble.vim | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim index c74cce4..7746b23 100644 --- a/src/testdir/test_vim9_disassemble.vim +++ b/src/testdir/test_vim9_disassemble.vim @@ -1761,6 +1761,74 @@ def Test_disassemble_typecast() instr) enddef +def Test_disassemble_object_cast() + # Downcasting. + var lines =<< trim END + vim9script + class A + endclass + class B extends A + var mylen: number + endclass + def F(o: A): number + return (<B>o).mylen + enddef + + g:instr = execute('disassemble F') + END + v9.CheckScriptSuccess(lines) + assert_match('\<SNR>\d*_F\_s*' .. + 'return (<B>o).mylen\_s*' .. + '0 LOAD arg\[-1\]\_s*' .. + '1 CHECKTYPE object<B> stack\[-1\]\_s*' .. + '2 OBJ_MEMBER 0\_s*' .. + '3 RETURN\_s*', + g:instr) + + # Upcasting. + lines =<< trim END + vim9script + class A + var mylen: number + endclass + class B extends A + endclass + def F(o: B): number + return (<A>o).mylen + enddef + + g:instr = execute('disassemble F') + END + v9.CheckScriptSuccess(lines) + assert_match('\<SNR>\d*_F\_s*' .. + 'return (<A>o).mylen\_s*' .. + '0 LOAD arg\[-1\]\_s*' .. + '1 OBJ_MEMBER 0\_s*' .. + '2 RETURN\_s*', + g:instr) + + # Casting, type is not statically known. + lines =<< trim END + vim9script + class A + endclass + class B extends A + endclass + def F(o: any): any + return <A>o + enddef + + g:instr = execute('disassemble F') + END + v9.CheckScriptSuccess(lines) + assert_match('\<SNR>\d*_F\_s*' .. + 'return <A>o\_s*' .. + '0 LOAD arg\[-1\]\_s*' .. + '1 CHECKTYPE object<A> stack\[-1\]\_s*' .. + '2 RETURN\_s*', + g:instr) +enddef + def s:Computing() var nr = 3 var nrres = nr + 7 @@ -3496,4 +3564,26 @@ def Test_disassemble_compound_op_in_closure() unlet g:instr enddef +def Test_disassemble_member_initializer() + var lines =<< trim END + vim9script + class A + var l: list<string> = [] + var d: dict<string> = {} + endclass + g:instr = execute('disassemble A.new') + END + v9.CheckScriptSuccess(lines) + # Ensure SETTYPE is emitted and that matches the declared type. + assert_match('new\_s*' .. + '0 NEW A size \d\+\_s*' .. + '1 NEWLIST size 0\_s*' .. + '2 SETTYPE list<string>\_s*' .. + '3 STORE_THIS 0\_s*' .. + '4 NEWDICT size 0\_s*' .. + '5 SETTYPE dict<string>\_s*' .. + '6 STORE_THIS 1', g:instr) + unlet g:instr +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |