From a4e9136f68a40b1cb0eb6df5a5f06603224a87f4 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 19 Sep 2024 06:05:19 +0200 Subject: Merging upstream version 2:9.1.0698. Signed-off-by: Daniel Baumann --- src/testdir/test_vim9_disassemble.vim | 90 +++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'src/testdir/test_vim9_disassemble.vim') 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 (o).mylen + enddef + + g:instr = execute('disassemble F') + END + v9.CheckScriptSuccess(lines) + assert_match('\\d*_F\_s*' .. + 'return (o).mylen\_s*' .. + '0 LOAD arg\[-1\]\_s*' .. + '1 CHECKTYPE object 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 (o).mylen + enddef + + g:instr = execute('disassemble F') + END + v9.CheckScriptSuccess(lines) + assert_match('\\d*_F\_s*' .. + 'return (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 o + enddef + + g:instr = execute('disassemble F') + END + v9.CheckScriptSuccess(lines) + assert_match('\\d*_F\_s*' .. + 'return o\_s*' .. + '0 LOAD arg\[-1\]\_s*' .. + '1 CHECKTYPE object 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 = [] + var d: dict = {} + 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\_s*' .. + '3 STORE_THIS 0\_s*' .. + '4 NEWDICT size 0\_s*' .. + '5 SETTYPE dict\_s*' .. + '6 STORE_THIS 1', g:instr) + unlet g:instr +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker -- cgit v1.2.3