diff src/ov-class.cc @ 9691:318e0cdd31bd

improve OOP subsref handling
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 05 Oct 2009 10:20:18 +0200
parents 3d0d2bda3a0f
children 0df32e0b2074
line wrap: on
line diff
--- a/src/ov-class.cc	Mon Oct 05 07:53:29 2009 +0200
+++ b/src/ov-class.cc	Mon Oct 05 10:20:18 2009 +0200
@@ -464,27 +464,32 @@
 	  count++;
 	  args(0) = octave_value (this);
 
+          // FIXME: for Matlab compatibility, let us 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.
+          // Note that Octave does not actually need this, since it will
+          // be able to properly react to varargout a posteriori.
           bool maybe_cs_list_query = (type[0] == '.' || type[0] == '{'
                                       || (type.length () > 1 && type[0] == '('
                                           && type[1] == '.'));
 
-          if (nargout == 1 && maybe_cs_list_query)
+          int true_nargout = nargout;
+
+          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 ();
-              octave_idx_type true_nargout = numel (tmp);
-              if (! error_state)
-                {
-                  tmp = feval (meth.function_value (), args, true_nargout);
-                  if (true_nargout != 1)
-                    retval(0) = octave_value (tmp, true);
-                  else
-                    retval = tmp;
-                }
+              true_nargout = numel (tmp);
             }
-          else
-            retval = feval (meth.function_value (), args, nargout);
+
+          retval = feval (meth.function_value (), args, true_nargout);
+
+          // Since we're handling subsref, return the list in the first value
+          // if it has more than one element, to be able to pass through
+          // rvalue1 calls. 
+          if (retval.length () > 1)
+            retval = octave_value (retval, true);
 	}
       else
 	{