# HG changeset patch # User Petter T. # Date 1707950328 -3600 # Wed Feb 14 23:38:48 2024 +0100 # Branch bytecode-interpreter # Node ID cecc0808298fe04e7cdea3fded89b3b5493eb528 # Parent f1e32a79b7691916d60600aab2c0675d9431cb85 Fix cs-list escape from matrix in bytecode interpreter (bug #65308) A '{:}' expansion inside a matrix inside an anonymous function made the cs-list escape the matrix when nargout was not 1, due to the expansion inheriting the nargout value from the parent function. Check the "special nargout -1" flag is not active, before pushing any "inherit nargout from parent function" opcode. * pt-bytecode-walk.cc: Chech flag * bytecode_anon_handles.m: Add test diff -r f1e32a79b769 -r cecc0808298f libinterp/parse-tree/pt-bytecode-walk.cc --- a/libinterp/parse-tree/pt-bytecode-walk.cc Wed Feb 14 23:38:48 2024 +0100 +++ b/libinterp/parse-tree/pt-bytecode-walk.cc Wed Feb 14 23:38:48 2024 +0100 @@ -5539,7 +5539,8 @@ arg_name_entry.m_obj_name = first_expression->name (); int slot = SLOT (first_expression->name ()); - MAYBE_PUSH_ANON_NARGOUT_OPEXT (nargout); + if (! m1_magic_nargout) + MAYBE_PUSH_ANON_NARGOUT_OPEXT (nargout); PUSH_CODE (INSTR::INDEX_STRUCT_CALL); if (m1_magic_nargout) PUSH_CODE (1); // Note, 1, not -1. Since there is no subsref in INDEX_STRUCT_CALL @@ -5549,7 +5550,8 @@ } else { - MAYBE_PUSH_ANON_NARGOUT_OPEXT (nargout); + if (! m1_magic_nargout) + MAYBE_PUSH_ANON_NARGOUT_OPEXT (nargout); PUSH_CODE (INSTR::INDEX_STRUCT_CALL); if (m1_magic_nargout) PUSH_CODE (1); // Note, 1, not -1. @@ -5566,7 +5568,8 @@ // // If it is, the following opcode is skipped for '(' type calls since those eat the args, whereas it is executed // for '{' or '.' types. - MAYBE_PUSH_ANON_NARGOUT_OPEXT (nargout); + if (! m1_magic_nargout) + MAYBE_PUSH_ANON_NARGOUT_OPEXT (nargout); PUSH_CODE (INSTR::INDEX_STRUCT_SUBCALL); if (m1_magic_nargout) PUSH_CODE (-1); diff -r f1e32a79b769 -r cecc0808298f test/compile/bytecode_anon_handles.m --- a/test/compile/bytecode_anon_handles.m Wed Feb 14 23:38:48 2024 +0100 +++ b/test/compile/bytecode_anon_handles.m Wed Feb 14 23:38:48 2024 +0100 @@ -131,6 +131,21 @@ end assert (threw); + + # bug 65308 + f = @(x) [x{:}]; # The cs-list "escaped" the matrix' claws + threw = false; + try + [a, b] = f({5,9}); # The bug made a=5 and b=9 + catch ex + assert (strfind (ex.message, "element number 2 undefined in return list")) + threw = true; + end + + assert (threw) + + a = f({5,9}); + assert (a == [5,9]) end function [x, y, z] = try_isargout ()