Mercurial > octave
changeset 31652:a18897e4c7b5
classdef: call subsref method with correct nargout value (bug #48693)
* /libinterp/octave-value/ov-classdef.cc (octave_classdef::subsref): Correct
the nargout value for classdef subsref calls by checking the number of values
the indexing argument addresses, using the same code used by the non-classdef
subsref method.
* /test/bug-48693/bug-48693.tst, bug48693.m, module.mk: Add simple test
function files to verify subsref behavior.
author | Fernando Alvarruiz <feralber@upvnet.upv.es> |
---|---|
date | Wed, 07 Dec 2022 22:37:28 -0500 |
parents | beb7f91a0a97 |
children | 972dcc46bb41 |
files | libinterp/octave-value/ov-classdef.cc test/bug-48693/bug-48693.tst test/bug-48693/bug48693.m test/bug-48693/module.mk |
diffstat | 4 files changed, 36 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-classdef.cc Wed Dec 07 14:26:59 2022 +0100 +++ b/libinterp/octave-value/ov-classdef.cc Wed Dec 07 22:37:28 2022 -0500 @@ -91,8 +91,29 @@ count++; args(0) = octave_value (this); + // Attempt to set up a proper value for nargout at least in the + // simple case where the cs-list-type expression - i.e., {} or + // ().x, is the leading one. + bool maybe_cs_list_query = (type[0] == '.' || type[0] == '{' + || (type.length () > 1 && type[0] == '(' + && type[1] == '.')); + + if (maybe_cs_list_query) + { + // Set up a proper nargout for the subsref call by calling numel. + octave_value_list tmp; + if (type[0] != '.') tmp = idx.front (); + nargout = xnumel (tmp); + } + retval = meth.execute (args, nargout, true, "subsref"); + // Since we're handling subsref, if the list has more than one + // element, return it as a comma-separated list so that we can + // pass it to the evaluator + if (retval.length () > 1) + retval = octave_value (retval); + return retval; } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-48693/bug-48693.tst Wed Dec 07 22:37:28 2022 -0500 @@ -0,0 +1,3 @@ +%!test +%! x = bug48693(); +%! assert ({x{1:10}}, num2cell (zeros(1,10)))