diff src/ov-class.cc @ 9331:a76f391a3d02

set up proper nargout for call to subsref method
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 11 Jun 2009 12:25:36 +0200
parents 67fc970dad7d
children 3930f8ce6430
line wrap: on
line diff
--- a/src/ov-class.cc	Thu Jun 11 11:12:02 2009 +0200
+++ b/src/ov-class.cc	Thu Jun 11 12:25:36 2009 +0200
@@ -446,7 +446,27 @@
 	  count++;
 	  args(0) = octave_value (this);
 
-	  return feval (meth.function_value (), args, nargout);
+          bool maybe_cs_list_query = (type[0] == '.' || type[0] == '{'
+                                      || (type.length () > 1 && type[0] == '('
+                                          && type[1] == '.'));
+
+          if (nargout == 1 && 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;
+                }
+            }
+          else
+            retval = feval (meth.function_value (), args, nargout);
 	}
       else
 	{