changeset 28194:36a27ecbfc83

maint: merge stable to default.
author John W. Eaton <jwe@octave.org>
date Wed, 08 Apr 2020 14:59:01 -0400
parents 450fe5371acd (current diff) 56c209ff0a08 (diff)
children 20dea4a919c0
files
diffstat 4 files changed, 60 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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 ())
--- 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;
--- 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
--- 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)