changeset 18439:d5aa615dcf4c

Fix package function call with magic "end" in arguments. * ov-classdef.cc (cdef_package::cdef_package_rep::meta_subsref): Don't handle the case "pack.fun", leave it up to the parse-tree to execute the package function. * pt-idx.cc (tree_index_expression::rvalue): If the (temporary) result of indexing is a function object, make sure it is executed if required.
author Michael Goffioul <michael.goffioul@gmail.com>
date Sat, 08 Feb 2014 17:10:01 -0500
parents e76d50d65278
children 96a495813047
files libinterp/octave-value/ov-classdef.cc libinterp/parse-tree/pt-idx.cc
diffstat 2 files changed, 49 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-classdef.cc	Sat Feb 08 13:35:00 2014 -0800
+++ b/libinterp/octave-value/ov-classdef.cc	Sat Feb 08 17:10:01 2014 -0500
@@ -3443,7 +3443,13 @@
 
                       if (! error_state)
                         {
-                          if (type.size () == 1 ||
+                          // NOTE: the case where the package query is the last
+                          // part of this subsref index is handled in the parse
+                          // tree, because there is some logic to handle magic
+                          // "end" that makes it impossible to execute the
+                          // function call at this stage.
+
+                          if (type.size () > 1 &&
                               ! fcn->is_postfix_index_handled (type[1]))
                             {
                               octave_value_list tmp_args;
--- a/libinterp/parse-tree/pt-idx.cc	Sat Feb 08 13:35:00 2014 -0800
+++ b/libinterp/parse-tree/pt-idx.cc	Sat Feb 08 17:10:01 2014 -0500
@@ -363,7 +363,7 @@
                   // that argument list so we can pass the appropriate
                   // value to the built-in end function.
 
-                  const octave_value_list tmp_list
+                  octave_value_list tmp_list
                     = tmp.subsref (type.substr (tmpi, i - tmpi), idx, nargout);
 
                   tmp = tmp_list.length () ? tmp_list(0) : octave_value ();
@@ -375,6 +375,26 @@
 
                   if (error_state)
                     break;
+
+                  if (tmp.is_function ())
+                    {
+                      octave_function *fcn = tmp.function_value (true);
+
+                      if (fcn && ! fcn->is_postfix_index_handled (type[i]))
+                        {
+                          octave_value_list empty_args;
+
+                          tmp_list = tmp.do_multi_index_op (1, empty_args);
+                          tmp = (tmp_list.length ()
+                                 ? tmp_list(0) : octave_value ());
+
+                          if (tmp.is_cs_list ())
+                            gripe_indexed_cs_list ();
+
+                          if (error_state)
+                            break;
+                        }
+                    }
                 }
             }
 
@@ -412,8 +432,27 @@
         }
 
       if (! error_state)
-        retval = tmp.subsref (type.substr (tmpi, n - tmpi), idx, nargout,
-                              lvalue_list);
+        {
+          retval = tmp.subsref (type.substr (tmpi, n - tmpi), idx, nargout,
+                                lvalue_list);
+
+          octave_value val = retval.length () ? retval(0) : octave_value ();
+
+          if (! error_state && val.is_function ())
+            {
+              octave_function *fcn = val.function_value (true);
+
+              if (fcn)
+                {
+                  octave_value_list empty_args;
+
+                  retval = (lvalue_list
+                            ? val.do_multi_index_op (nargout, empty_args,
+                                                     lvalue_list)
+                            : val.do_multi_index_op (nargout, empty_args));
+                }
+            }
+        }
     }
 
   return retval;