# HG changeset patch # User John W. Eaton # Date 1586372341 14400 # Node ID 36a27ecbfc83e24039bef69d5ae6bf774011a870 # Parent 450fe5371acd65618f95cf9b4f60899f8ae8e6c2# Parent 56c209ff0a08713d62be7a2c6d50898b242357d7 maint: merge stable to default. diff -r 450fe5371acd -r 36a27ecbfc83 libinterp/parse-tree/oct-lvalue.cc --- a/libinterp/parse-tree/oct-lvalue.cc Tue Apr 07 18:24:51 2020 +0200 +++ b/libinterp/parse-tree/oct-lvalue.cc Wed Apr 08 14:59:01 2020 -0400 @@ -80,6 +80,20 @@ return retval; } + bool octave_lvalue::index_is_colon (void) const + { + bool retval = false; + + if (m_idx.size () == 1) + { + octave_value_list tmp = m_idx.front (); + + retval = (tmp.length () == 1 && tmp(0).is_magic_colon ()); + } + + return retval; + } + void octave_lvalue::do_unary_op (octave_value::unary_op op) { if (! is_black_hole ()) diff -r 450fe5371acd -r 36a27ecbfc83 libinterp/parse-tree/oct-lvalue.h --- a/libinterp/parse-tree/oct-lvalue.h Tue Apr 07 18:24:51 2020 +0200 +++ b/libinterp/parse-tree/oct-lvalue.h Wed Apr 08 14:59:01 2020 -0400 @@ -77,6 +77,8 @@ bool index_is_empty (void) const; + bool index_is_colon (void) const; + void do_unary_op (octave_value::unary_op op); octave_value value (void) const; diff -r 450fe5371acd -r 36a27ecbfc83 libinterp/parse-tree/pt-assign.cc --- a/libinterp/parse-tree/pt-assign.cc Tue Apr 07 18:24:51 2020 +0200 +++ b/libinterp/parse-tree/pt-assign.cc Wed Apr 08 14:59:01 2020 -0400 @@ -226,14 +226,24 @@ // // [varargout{1:nargout}] = fcn (args); // + // or + // + // varargout = cell (1, nargout); + // [varargout{1:nargout}] = fcn (args); + // + // or + // + // varargout = cell (1, nargout); + // [varargout{:}] = fcn (args); + // // Will work the same as calling fcn directly when nargout // is 0 and fcn produces more than one output even when - // nargout is 0. This only works if varargout has not yet - // been defined. See also bug #43813. + // nargout is 0. See also bug #43813. if (lvalue_list.size () == 1 && nel == 0 && n > 0 - && ! ult.is_black_hole () && ult.is_undefined () - && ult.index_type () == "{" && ult.index_is_empty ()) + && ! ult.is_black_hole () && ult.index_type () == "{" + && (ult.index_is_empty () + || (ult.is_defined () && ult.index_is_colon ()))) { // Convert undefined lvalue with empty index to a cell // array with a single value and indexed by 1 to diff -r 450fe5371acd -r 36a27ecbfc83 test/args.tst --- a/test/args.tst Tue Apr 07 18:24:51 2020 +0200 +++ b/test/args.tst Wed Apr 08 14:59:01 2020 -0400 @@ -124,6 +124,36 @@ %! [s, t, u, v] = f (1, 2, 3); %! assert ([s t u v], [1 2 3 4]); +## Wrapper functions +%!function [x, y, z] = f (varargin) +%! assert (nargin, 0); +%! assert (nargout, 0); +%! x = 3; +%! y = 2; +%! z = 1; +%!endfunction +%!function varargout = wrapper_1 (varargin) +%! assert (nargout, 0); +%! [varargout{1:nargout}] = f (); +%!endfunction +%!function varargout = wrapper_2 (varargin) +%! assert (nargout, 0); +%! varargout = cell (1, nargout); +%! [varargout{1:nargout}] = f (); +%!endfunction +%!function varargout = wrapper_3 (varargin) +%! assert (nargout, 0); +%! varargout = cell (1, nargout); +%! [varargout{:}] = f (); +%!endfunction +%!test +%! wrapper_1 (); +%! assert (ans, 3); +%! wrapper_2 (); +%! assert (ans, 3); +%! wrapper_3 (); +%! assert (ans, 3); + ## Test default arguments ## numeric %!function f (x = 0)